CodeSniffer is a tool to detect coding standard violation for PHP, CSS and Javascript. It is really useful to check if the codes you made violate the coding standard you defined. When you work in a team, this tool can help a lot. Today, I'm going to show how to setup CodeSniffer on PHPStorm.
Installation
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 /Users/masbugan/.composer/vendor/bin/phpcs
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.
Test CodeSniffer
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.
Summary
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.