https://jason.pureconcepts.net/2012/11/php-coding-standards/
You can download PHP CodeSniffer. If you have PEAR installed, it’s easier:
pear install PHP_CodeSniffer Verify PHP CodeSniffer with:
phpcs --version
Note: If you receive warnings, your PHP include_path likely does not include the PEAR directory. Check your PEAR installation to resolve this issue.
You can run PHP CodeSniffer against an entire directory.
phpcs --standard=PSR2 api/
Format legacy code
Since I just adopted the PSR-2 coding standard, I had several violations in my current projects. However, as traditional lazy developer, I didn’t want to edit hundreds of lines of code.
I found PHP CS Fixer. It auto-formats code to meet PSR-2 (among others). While it doesn’t correct everything, it fixes the tedious ones.
php-cs-fixer fix api/ --level=psr2 --dry-run Note: I added --dry-run for demonstration purposes. Remove it to update your files.
Go forth and be a better PHP developer A good developer should follow a coding standard. While I am advocating PSR-2 here, it is really up to you. What matters is that you follow it strictly. Hopefully the tools above can help you do so.