phpstorm phpcs and wpcs


I have installed phpcs, php cs fixer and wpcs via composer and globally. I have set them under Settings/Preferences | Languages & Frameworks | PHP | Quality Tools | Code Sniffer. When I try to my own custom coding standard I get a error.

phpcs: PHP Fatal error: Uncaught Error: Class 'WordPress\Sniffs\Security\NonceVerificationSniff' not found in C:\Users\Robert\AppData\Roaming\Composer\vendor\wpcs\WordPress\Sniffs\CSRF\NonceVerificationSniff.php:27

I have checked the path and NonceVerificationSniff.php is indeed there and it extending the class so I don't know what the problem is?


When I try to my own custom coding standard I get a error.

Please describe your exact actions - what do you click, where the coding standard reside. Thank you!


This is when I am trying to enable. --

This is when I am trying to select the coding standard. --

When I try to select "custom" is when the error occurs.

I am trying to use this as a example to build from --

<?xml version="1.0"?>
<ruleset name="Robert Parker">
<description>The PHP CodeSniffer rules.</description>
<!-- Exclude the Composer Vendor directory. -->
<!-- Exclude the Node Modules directory. -->
<!-- Exclude all Javascript files. -->
<!-- Exclude minified CSS file. -->

<rule ref="WordPress">
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
<exclude name="WordPress.Security.NonceVerification"/>



Basically, what PhpStorm is trying to run is phpcs --standard="C:\Users\exact\Documents\codesniffer.ruleset.xml" file.php.
Does this command work from CMD for you?


I was able to run PHP_CodeSniffer with your standard in PhpStorm, but I had to add these installed paths first as otherwise it said that the referenced sniff WordPress is missing:


I never had the exception you see, so it must be something about your installation. Please check how it runs from CMD.


It will not run from command prompt. 

phpcs --standard="C:\Users\exact\Documents\codesniffer.ruleset.xml" file.php

PHP Fatal error: Uncaught Error: Class 'WordPress\Sniffs\Security\NonceVerificationSniff' not found in C:\Users\exact\AppData\Roaming\Composer\vendor\wpcs\WordPress\Sniffs\CSRF\NonceVerificationSniff.php:27
Stack trace:
#0 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\autoload.php(167): include()
#1 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Ruleset.php(1136): PHP_CodeSniffer\Autoload::loadFile('C:\\Users\\exact\\...')
#2 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Ruleset.php(217): PHP_CodeSniffer\Ruleset->registerSniffs(Array, Array, Array)
#3 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php(301): PHP_CodeSniffer\Ruleset->__construct(Object(PHP_CodeSniffer\Config))
#4 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Runner.php(70): PHP_CodeSniffer\Runner->init()
#5 C:\Users\exact\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcs(18): PHP_CodeSniffe in C:\Users\exact\AppData\Roaming\Composer\vendor\wpcs\WordPress\Sniffs\CSRF\NonceVerificationSniff.php on line 27


Running phpcs --standard="C:\Users\exact\Documents\codesniffer.ruleset.xml" file.php would run it using Global phpcs executable & it would search for WPCS in a global composer installation. I believe you didn't install WPCS globally that's why this fails.

According to their docs phpcs.xml (note that ruleset should be named .phpcs.xml, phpcs.xml, .phpcs.xml.dist or phpcs.xml.dist) should be placed in the directory from which you run the CodeSniffer.

Please try to setup the project & phpcs config this way & try launching it in console - it should be working this way.

As for PhpStorm - I believe there's indeed an issue with phpcs custom ruleset & relative paths. I've added this scenario as an example at I hope we' will be able to investigate this issue closely with a responsible developer.


I try to install it globally -- composer global require "wp-coding-standards/wpcs=*"

It made no difference. I can check the path and the document is there with the extended class so I don't understand.


What is strange is the default coding standards are working -- WordPress, WordPress-Core, WordPress-Docs,WordPress-Extra, WordPress-VIP

phpcs --standard=WordPress file.php


What Dmitry suggested is exactly opposite - he suggested that you install PHP_CodeSniffer and the coding standards into the project, not globally.

Also, since it doesn't work from CMD, apparently the issue is not on the PhpStorm side. Honestly, it's hard to say what's going wrong there - as I said, your ruleset worked for me like a charm.


@Dmitry Tronin I installed it globally and it still fails. If I use any of the defined code standards it is working. I renamed my coding standard and I get the same error.


It is with my installation fo phpcs & wpcs. I don't know what yet but I got the same error trying to use it in Sublime Text 3. That is why I think it is with my installation and not phpstorm.


Try to start from the scratch: delete the wpcs & phpcs (if it's an option) & install and set it up anew using their documentation.


I found out my problem. I had two dependencies of wpcs and one was not installed. It was reading from that and why I got the error. Thanks for your help!


Please sign in to leave a comment.