Advanced PHP Code Sniffer Options in PhpStorm 5.0
New version allows to specify your own coding standard with a root directory outside default PHP Code Sniffer’s Standards directory. In addition it provides a better control on PhpStorm integration with the tool to optimize its use in a particular environment.
Specfying Your Own Coding Standard
If you have created your own coding standard according to this tutorial, you can specify it in PHP Code Sniffer validation inspection settings. Choose Settings|Inspections|PHP|PHP Code Sniffer validation to get the following options panel:
Select “Custom” in coding standard combo box and click […] button next to the field. You will get “Custom Coding Standard” dialog which allows you to give a root directory of your coding standard. The directory must contain a ruleset.xml file.
Since there is no guarantee that ruleset.xml is valid or points to valid rules, you may start getting error notifications from PHP Code Sniffer every time you open or edit a PHP file. Here is an example:
If this is the case, you have to check your rules and make sure they work when used directly with phpcs command line tool.
A note on sharing a ruleset with the team via project (VCS)
If you would like to share the ruleset with your team, you can put it under project (and VCS) root and specify your coding standard root in inspection settings above. But in order to share these settings, make sure that “Share profile” flag of the selected profile is on like in this example:
Running PHP Code Sniffer in Batch Mode
In version 5.0 PHP Code Sniffer inspection can be run in batch mode just like any other inspection. If you choose Code|Inspect code, you may get something like this:
Note the results from PHP Code Sniffer validation.
Advanced Tool Options
First of all PHP Code Sniffer tool settings are moved to a separate panel under PHP settings to distinguish them from inspection parameters which can be shared via project. Tool settings are always local (PC-specific). Currently you may find the following if you choose Settings|PHP|Code Sniffer:
PHP Code Sniffer path is the same as it used to be and “Validate” button is there too. But there are two new options:
- Maximum number of messages per file: limits the total number of messages reported to the given number (14 in the example above), all other messages are rejected and a special warning “Too many PHP Code Sniffer messages” is shown in the code.
- Tool process timeout: allows to control maximum time in which a result from PHP Code Sniffer should be expected. If this time is exceeded, the process is killed to prevent excess CPU and memory usage. Compared to the previous solution where the timeout was hard-coded, this gives you a possibility to fine tune PHP Code Sniffer process behavior depending on PC configuration and specific rule sets.
More Information and Your Feedback
If you are reading about PHP Code Sniffer integration in PhpStorm for the first time, I recommend to take a look at the previous post here. If you give the feature a try, please don’t forget that your feedback is extremely important for us. Don’t hesitate to submit any kind of findings and/or new ideas in YouTrack. And thank you for using our IDE!
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…