Linting PHP files with Travis

Continuous Integration, Quick Tip

Travis is an awesome tool and my goto for Continues Integration and Continues Deployment. A quick win is to add a PHP linter:

before_script:
- if find . -name "*.php" ! -path "./vendor/*" -exec php -l {} \; | grep -v "No syntax errors detected"; then exit 1; fi

If you have a lot of files that can be quite slow as it processes 1 file at a time. If we tweak the command a bit we can process 8 files at the same time:

before_script:
- if find . -name "*.php" ! -path "./vendor/*" -print0 | xargs -0 -n 1 -P 8 php -l | grep -v "No syntax errors detected"; then exit 1; fi

This will lint you PHP files before executing you tests. It only outputs files that have an error. Files that are OK are skipped.