There are two ways to install CodeSniffer, using PEAR or using Composer. I prefer use Composer for this one. You need to execute command below to install CodeSniffer
[php] composer global require "squizlabs/php_codesniffer=*" [/php]
We install CodeSniffer as global command so PHPStorm can always make reference to it. This command will install CodeSniffer in this path
Setup on PHPStorm
Here is how to insert reference for CodeSniffer
- Go to menu Preferences
- Choose PHP -> Code Sniffer
- Insert the CodeSniffer path to the input text and click Validate
- Click Apply and you are done
Change CodeSniffer Setting
To make CodeSniffer run, you need to set PHPStorm to use it when inspect codes. Here is the step
- Go to Preferences
- Go to Inspections -> PHP
- Check the PHP Code Sniffer Validation
- You can also define coding standard you want there.
CodeSniffer can be executed via menu Code -> Inspect Code. You can choose to inspect whole project or just current file. Then PHPStorm will list the inspection result.
That is it how to setup CodeSniffer on PHPStorm. You will be really helped with this tool to make your codes always match with defined coding standard.