Last days some pull requests injected some non-standard code into the Joomla! master branch. This is a great moment to remember how to setup PHP CodeSniffer to ensure that our code is standard compliant.
Joomla! has a repository on Github with its coding standards. The README contains all the required info to setup phpcs:
1Install CodeSniffer
The CodeSniffer integrated Ubuntu is usually too old to setup it to work with Joomla! Standards that require version 1.3+. So we better install the latest CodeSniffer with PEAR:
sudo pear install PHP_CodeSniffer
2Install Joomla! standards
We can clone directly the Joomla! standard Github repo into the CodeSniffer standards folder with the command:
sudo git clone http://github.com/joomla/coding-standards.git `pear config-get php_dir`/PHP/CodeSniffer/Standards/Joomla
That's all. Now you can use the Joomla standard like:
phpcs --standard=Joomla index.php
This will validate manually the index.php file in the current folder and show you any errors ocurred.
Best way to use phpcs is integrating it with your IDE.
Integration with Eclipse, Netbeans and PHPStorm is described in:
http://docs.joomla.org/Joomla_CodeSniffer
Integration with Sublime Text 2 is described in our article:
Sublime Text 2 for Joomla! development