1
votes

I'm working on a WordPress project using PHPStorm. To beautify my code I downloaded the following CodeSniffer rules for WP and put them in my build directory in my project folder: https://github.com/mrchrisadams/WordPress-Coding-Standards

Now When I set PHPStorm to use the ruleset.xml, I get the following error:

PHP Code Sniffer
phpcs: PHP Fatal error: Cannot redeclare class WordPress_Sniffs_Strings_DoubleQuoteUsageSniff in /var/www/projectname/build/CodeSniffer/Sniffs/Strings/DoubleQuoteUsageSniff.php on line 31
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpcs:0
PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37
PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:561
PHP 4. PHP_CodeSniffer->populateTokenListeners() /usr/share/phpPHP/CodeSniffer.php:458
PHP 5. PHP_CodeSniffer::autoload() /usr/share/php/PHP/CodeSniffer.php:0

I also work on another project (not at the same time) based on Drupal having its own ruleset.xml - it works without any problems.

Does anyone know that kind of issue?

3
Do a project-wide search (Edit | Find | Find in path) for class WordPress_Sniffs_Strings_DoubleQuoteUsageSniff (or very similar) -- looks like somehow you are loading this class twice (your autoloader issue??) -- it may give you some hints. - LazyOne

3 Answers

1
votes

This error is not related to PhpStorm and is being generated by PHP_CodeSniffer itself.

It appears when your Sniff classes are not properly named. They must strictly follow the directory structure and the file of the Sniff.

If your class is called WordPress_Sniffs_Strings_DoubleQuoteUsageSniff

it should be located in: /Standards/WordPress/Sniffs/Strings/DoubleQuoteUsageSniff.php

0
votes

It seems like your own ruleset is including this rule (WordPress Strings DoubleQuoteUsageSniff ) twice which may cause your ruleset to abort.

I would suggest you to look into your ruleset.xml and remove one of this two sniffs. It may be caused by including another ruleset first aswell.

0
votes

Also make sure that the folder that contains your sniff has the same name as specified in the ruleset.xml.

For example if your ruleset.xml says:

<ruleset name="Joomla">

or

<ruleset name="Wordpress">

The folder that contains all the sniffers may be named as:

/php/pear/PHP/CodeSniffer/Standards/Joomla/... <= inside you will have ruleset.xml and Sniffs folder

or

/php/pear/PHP/CodeSniffer/Standards/Wordpress/... <= inside you will have ruleset.xml and Sniffs folder