Linting PHP files with Travis

Continuous Integration, Quick Tip

Travis is an awesome tool and my go-to for Continuous Integration and Continuous 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 one 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 your PHP files before executing your tests. It only outputs files that have an error. Files that are OK are skipped.

Michiel Gerritsen
About the author

Michiel Gerritsen

Connect on LinkedIn

Founder of Control Alt Delete, a Magento agency specialised in testing, CI/CD and checkout integrations. Working with Magento since 2015, and board member of Mage-OS.

Missing anything?
What are you missing? X
Thank you for your feedback!