How to sniff our CakePHP code on Mavericks

First of all we have to have installed on our system PHP using homebrew you can follow my post PHP on Mavericks with Homebrew to accomplished it.

Then we have to install CodeSniffer using PEAR with the following command:

pear install PHP_CodeSniffer

We can check our PHPcs version with the following command:

phpcs --version

Then we have to install the specific CakePHP sniffer:

pear channel-discover

We could see the following error:

could not create lock file: fopen(/usr/local/Cellar/php55/5.5.9/lib/php/.lock): failed to open stream: Permission denied

If that´s your case you can run the following commands to change the permissions:

chmod -R ug+w /usr/local/Cellar/php55/5.5.9/lib/php

pear config-set php_ini /usr/local/etc/php/5.5/php.ini

And then try again the instalation:

pear channel-discover
pear install cakephp/CakePHP_CodeSniffer

Once we have everything installed we can use our Sniffer for CakePHP like that:

phpcs --standard=CakePHP ~/PATH/OUR_FILE.php