Skip to content

Instantly share code, notes, and snippets.

@mehranhadidi
Last active February 19, 2017 09:26
Show Gist options
  • Save mehranhadidi/ae5b5fc4f744d95c55f8244e2ca38399 to your computer and use it in GitHub Desktop.
Save mehranhadidi/ae5b5fc4f744d95c55f8244e2ca38399 to your computer and use it in GitHub Desktop.
php usefull tools

PHP Code sniffer

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment