photo credit: cobalt123 via photopin cc

Setup PHP CodeSniffer for PHPStorm on OSX

On Meet Magento 2014  I attended an interesting presentation about Continues Integration in Magento from Damian Luszczymak. One important aspect of Continuous Integration is that as a team of developers everyone should follow the same coding guidelines. If you use PHPStorm, you can use PHP CodeSniffer to ensure that the code you are writing as a team is readable by your colleagues.

“Why is this important?” you might ask. Well… if every programmer in your team is programming in the same style, it’s easier for programmer A to read, edit or debug the code of programmer B.

Setting it all up

PHP CodeSniffer

Installing PHP CodeSniffer on OSX is extremely easy. Just open up your best friend the terminal and install it:

Now, when all is set and done, check if PHP CodeSniffer works by entering the command phpcs  in your terminal. If all went well, you should see just a blinking cursor. You can press Ctrl+C now to exit it. If you get a bunch of PHP-errors telling you they can’t include a file, you need to update include_path  your in /etc/php.ini :
First locate where your pear is installed (on my system that’s /usr/local/pear ) and add this path including share/pear  as a path to your include_path  in /etc/php.ini :

Now executing phpcs  on your command line should not throw any errors.


Check where your phpcs  is located by executing which phpcs  in your terminal. In PHPStorm, you need to enter this path in the configuration at Project Settings > PHP > Code Sniffer. By clicking on the ‘Validate’-button you can check if everything is correct:

Screen Shot 2014-05-23 at 16.02.09
Now the second thing you need to do for your project configuration is at Project Settings > Inspections > PHP’ enable ‘PHP Code Sniffer Validation’ and select the Coding standard you wish to use. You might have to press the refresh button to see them all but they’re there:

Screen Shot 2014-05-23 at 16.03.08
That’s it: your PHPStorm now shows you where your code is not following the rules:

Screen Shot 2014-05-23 at 16.09.41

I also wrote a nice article in Dutch in response to Damian Luszczymaks’ presentation about Continuous Integration in Magento.

Update: I also found this nice tool to generate your own ruleset.

Visitors give this article an average rating of 3.5 out of 5.

How would you rate this article?

Leave a Reply