Checking your code with PHP Code Sniffer in PhpStorm 4.0
PhpStorm 4.0 allows you to check your code on the fly with PHP Code Sniffer (phpcs) just by opening a PHP file. The check is triggered every time you change something in the file thus making it extremely easy to get rid of problems reported by PHP Code Sniffer.
Initial Software Requirements
First you need to set up PHP Code Sniffer. You can find more information on site. Make sure you can actually run PHP Code Sniffer from command line: if you type “
phpcs --version“, you should get something like this:
PHP_CodeSniffer version 1.3.3 (stable) by Squiz Pty Ltd. (http://www.squiz.net)
Setting Up PHP Code Sniffer Validation Inspection
- Open Settings and navigate to Inspections|PHP|PHP Code Sniffer validation and check the inspection box.
- Now select a Code Sniffer path like it is shown below, for example:
- Click “Validate”. This is necessary to ensure that phpcs can be launched from IDE and will report problems. PhpStorm performs the validation by attempting to run “
phpcs --version“. On success it displays obtained phpcs version message and updates a list of coding standards (“Coding standard” combo box):
- Choose a coding standard you want (passed as a value of “
--standard” option) and optionally set the flag “Ignore warnings” (equivalent to “-n” option).
- Click OK.
Obtaining Validation Results
Now open a PHP file. Once phpcs will be run, you will see a number of warning messages reported by PHP Code Sniffer. For example:
Note that each message is prefixed with “phpcs” to distinguish it from PhpStorm’s own inspections.
Note that validating the file takes some time, so you may not see all the results instantly but in some cases, especially if the file is big, in few seconds. That doesn’t prevent though from editing the file.
Let us know what you think and please submit your feedback (bug reports, improvement suggestions) in YouTrack. This will help us to make
phpcs tool integration even better.
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…