Skip to content
Scott Dutton edited this page May 24, 2019 · 2 revisions

Basic Usage

All of the commands can read from stdin with placeholder -

phpcs --report=json | php vendor/bin/diffFilter --phpcs /tmp/diff.txt -

phpcs can be run with any options you normally have for example --standard=PSR2

This will exit with code 2 if any of the new/edited code fails the code standards check. The output is kept so you can see what the offending lines are and what the error is.

Strict mode (--phpcsStrict) turns warning to errors

Speeding up the build.

As diffFilter will only fail on lines changed, you can run just the changed files though phpcs

git diff $(git merge-base origin/master HEAD) --name-only --diff-filter=ACMR -- "*.php" > files.txt

This will generate a list of files to check, please note this will only include php files, if you use any other file extensions be sure to check them.

phpcs --report=json --file-list=files.txt > phpcs.json || true 

This will run only the changed files in this branch (assuming its branched from master) though phpcs, The speed will significantly increase as a result.