I hope you enjoyed the post and if there are issues or questions, please feel free to reach out to me via Email or on Github. PHP Code Sniffer helps achieve uniformity of code styles and having your editor automatically check for violations goes a long way in improving the quality of your codebase. Our code is now automatically being checked against our preferred standard and errors originating from PHPCS will be prefixed with phpcs. This way we can specify our preferences in the phpcs.xml file and have it applied across our project (irrespective of the tool we are using). In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.xml in our project directory), and apply your changes. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the Settings dialog, go to Editor > Inspections. You should now see a different error on the Quality Tools page telling you that CodeSniffer inspection is not enabled.Ĭode inspections are how PHPStorm detects (and corrects) problems such as dead code, misspellings, and of course, code style violations in your project. You can click the Validate button to confirm it’s working and click “Apply” when you are done.
#Phpstorm psr2 full
Specify the full path of the PHPCS executable in the new dialog that opens (which is $YOUR_COMPOSER_BIN_PATH/phpcs). Click the “three dots button” beside the dropdown highlighted below: Expand the PHP Code Sniffer on the Quality Tools page and select Local from the Configuration dropdown. PHPStorm natively supports code inspection with PHP_CodeSniffer, though configuring it is quite some work.įirst, launch the Settings dialog (Ctrl+Alt+S) and navigate to Languages & Frameworks > PHP > Quality Tools. Red lines should appear in all the places with violations as shown below: Note that it also searches your project root for existing rulesets (which is the purpose of the phpcs.xml file in our sample project). Once installed, restart VS Code and the plugin will automatically search your global composer path for a PHPCS installation.
#Phpstorm psr2 install
The next time you modify a PHP file and save, PHPCS should run automatically and report any violations that occur in the popup menu.
![phpstorm psr2 phpstorm psr2](https://user-images.githubusercontent.com/5716777/48770214-e208c600-ecbd-11e8-9e08-4ac9a951942b.png)
For a complete list of all the possible config options, you can look up the example settings in the plugin source code.