1

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?

lumio
  • 7,428
  • 4
  • 40
  • 56
  • 1
    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 Feb 13 '13 at 16:50

3 Answers3

1

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

PrestaShopDeveloper
  • 3,110
  • 3
  • 21
  • 30
0

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.

Björn K
  • 126
  • 1
  • 3
0

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
Javier
  • 1