Build a container that automatically formats Docker x Laravel code

Sep 6, 2020 PHP Laravel Docker php-cs-fixer

What is PHP CS Fixer?

PHP CS Fixer(PHPCodingStandardsFixer) is, as the name suggests, a tool that modifies PHP code to conform to coding conventions. ..

Premise

This article is a supplement to the above article.

Edit docker-compose.yml

services: services:
  cs:
    image: herloct / php-cs-fixer
    volumes:
      --./backend:/project

Add services.cs.

command

#Do not automatically format (difference display only)
$ docker-compose run cs fix --dry-run -v --diff --diff-format udiff ..

#Automatic shaping
$ docker-compose run cs fix -v --diff --diff-format udiff ..

Makefile

Since the command is long, it is good to prepare a Makefile.

dry-cs:
docker-compose run cs fix --dry-run -v --diff --diff-format udiff.
fix-cs:
docker-compose run cs fix -v --diff --diff-format udiff ..

You can execute it with the following command.

$ make dry-cs
$ make fix-cs

Reference