So I wanted to install PHP Code Sniffer. I’m running PHPStorm, Composer a Mac and MacPorts. This is how I did it.
composer global require "squizlabs/php_codesniffer=*"
- Add
~/.composer/vendor/bin/
to your path (usually via ~/bash_profile) - Check installed correctly on command line –
phpcs --version
Installing into PHPStorm
- Open PHP Storm
- Under PHPStorm->Preferences search for PHP Code Sniffer
- In Languages and Frameworks add new custom, use Local and select directory where code sniffer is installed (~/composer/vendor/bin/phpcs)
- Validate to ensure working
- Under Editor->Inspects select PHP Code Sniffer so that it now uses
Using the Code Sniffer in PHPStorm
- Goto Code->Inspect Code
- Select the php code you wish to inspect
- Good luck with the results
Using the Magento ECG RuleSet
If you are on Magento 1.x you may want to install the ECG ruleset. Steps to add to PHPStorm are:
composer require magento-ecg/coding-standard
- git clone the repo and then move it(!) to be under directory
CodeSniffer/Standards/Ecg
. If you don’t do this it complains! - Open PHPStorm Preferences, goto Inspections. Select Custom and enter the Ecg directory location
Using Magento 2 RuleSet
Same as ECG but take ruleset from Magento 2 github.