comment 0
/ wsakaren

Installing PHP Code Sniffer on a mac

So I wanted to install PHP Code Sniffer. I’m running PHPStorm, Composer a Mac and MacPorts. This is how I did it.

  1. composer global require "squizlabs/php_codesniffer=*"
  2. Add ~/.composer/vendor/bin/ to your path (usually via ~/bash_profile)
  3. Check installed correctly on command line – phpcs --version

Installing into PHPStorm

  1. Open PHP Storm
  2. Under PHPStorm->Preferences search for PHP Code Sniffer
  3. In Languages and Frameworks add new custom, use Local and select directory where code sniffer is installed (~/composer/vendor/bin/phpcs)
  4. Validate to ensure working
  5. Under Editor->Inspects select PHP Code Sniffer so that it now uses

Using the Code Sniffer in PHPStorm

  1. Goto Code->Inspect Code
  2. Select the php code you wish to inspect
  3. 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:

  1. composer require magento-ecg/coding-standard
  2. git clone the repo and then move it(!) to be under directory CodeSniffer/Standards/Ecg. If you don’t do this it complains!
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *