- The
-aflag instructs phpcs to execute interactively, so then you can edit the files and re-check it again with no need to run the same phpcs command again. Awesome, eh? - The Git part:
git status --porcelainwill show us all files and their state:??for a new one,Mfor modified;- We combine
egrepandcutto give us exactly what we want, a perfect list. - We put this as a subcommand to pass the expected file list to phpcs.
- Docker here is a mere tool. You can enjoy the same functionality with or without it 😉
docker run -it --rm \
-v $(pwd):/mycode \
-w /mycode \
devdrops/php-toolbox \
phpcs -a --standard=PSR2 \
$(git status --porcelain | egrep "^(\ M|\?\?)" | cut -c 4-)
FIX
git status --porcelain | egrep "^[ M?]" | cut -c 4-will also provide the deleted files, which will break phpcs execution. Instead, usegit status --porcelain | egrep "^(\ M|\?\?)" | cut -c 4-to avoid those deleted files.