Hi. I installed code sniffer (2.5.1) and coder using composer (tells me I'm using version ^8.2 for drupal/coder), but I'm getting the following error all the time in PHP Storm:

phpcs: Fatal error: Uncaught exception 'PHP_CodeSniffer_Exception' with message 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found' in /Users/charles/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/Drupal/Sniffs/Commenting/FileCommentSniff.php:13 Stack trace: #0 /Users/charles/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php(1353): include_once() #1 /Users/charles/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php(560): PHP_CodeSniffer->registerSniffs(Array, Array)

Is this to do with the code sniffer version, as mentioned here: https://www.drupal.org/node/2397017 or could it be something else?

I understand that code sniffer removed the comment parser from recent versions - so is that the problem, and I should be using an earlier version?

Thanks :-)

Comments

foxtrotcharlie created an issue. See original summary.

klausi’s picture

Status: Active » Postponed (maintainer needs more info)

looks like you have some global old version of phpcs installed. Did you follow https://www.drupal.org/node/1419988 ? What is the output of "which phpcs" in your terminal? What does "ls -l" say on that file?

foxtrotcharlie’s picture

Status: Postponed (maintainer needs more info) » Active

Thanks @klausi - yes I did follow those instructions but perhaps I missed something...Here's the output of the commands you mentioned:

which phpcs:

/Users/charles/.composer/vendor/bin/phpcs

-l /Users/charles/.composer/vendor/bin/phpcs

lrwxr-xr-x  1 charles  staff  42 Mar 19  2016 /Users/charles/.composer/vendor/bin/phpcs -> ../squizlabs/php_codesniffer/scripts/phpcs

which composer:

/usr/local/bin/composer

composer global show:

Changed current directory to /Users/charles/.composer
alchemy/zippy                      0.3.5   Zippy, the archive manager companion
composer/installers                v1.1.0  A multi-framework Composer library installer
doctrine/collections               v1.3.0  Collections Abstraction library
drupal/coder                       8.2.8   Coder is a library to review Drupal code.
drupal/console                     0.11.3  The Drupal Console is a CLI tool to generate boilerplate code, interact and deb...
gabordemooij/redbean               v4.3.2  RedBeanPHP ORM
guzzlehttp/guzzle                  6.2.0   Guzzle is a PHP HTTP client library
guzzlehttp/promises                1.2.0   Guzzle promises library
guzzlehttp/psr7                    1.3.1   PSR-7 message implementation
ircmaxell/password-compat          v1.0.4  A compatibility library for the proposed simplified password hashing algorithm:...
padraic/humbug_get_contents        1.0.4   Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+
padraic/phar-updater               1.0.3   A thing to make PHAR self-updating easy and secure.
phpseclib/phpseclib                2.0.2   PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2,...
psr/http-message                   1.0     Common interface for HTTP messages
psr/log                            1.0.0   Common interface for logging libraries
squizlabs/php_codesniffer          2.5.1   PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations ...
stecman/symfony-console-completion 0.5.1   Automatic BASH completion for Symfony Console Component based applications.
symfony/config                     v2.8.8  Symfony Config Component
symfony/console                    v2.8.8  Symfony Console Component
symfony/css-selector               v2.8.8  Symfony CssSelector Component
symfony/debug                      v2.8.8  Symfony Debug Component
symfony/dependency-injection       v2.8.8  Symfony DependencyInjection Component
symfony/dom-crawler                v2.8.8  Symfony DomCrawler Component
symfony/event-dispatcher           v2.8.8  Symfony EventDispatcher Component
symfony/filesystem                 v2.8.8  Symfony Filesystem Component
symfony/finder                     v2.8.8  Symfony Finder Component
symfony/http-foundation            v2.8.8  Symfony HttpFoundation Component
symfony/polyfill-mbstring          v1.2.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54             v1.2.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55             v1.2.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/process                    v3.1.2  Symfony Process Component
symfony/translation                v2.8.8  Symfony Translation Component
symfony/yaml                       v2.8.8  Symfony Yaml Component
twig/twig                          v1.24.1 Twig, the flexible, fast, and secure template language for PHP

Thanks :-)

klausi’s picture

Status: Active » Fixed

So it looks like your PHPCS setup is broken. /Users/charles/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/Drupal/Sniffs/Commenting/FileCommentSniff.php should not exist because Coder is not part of PHPCS. Or did you link some version of Coder there?

I would suggest that you remove /Users/charles/.composer/vendor/squizlabs/php_codesniffer and install it again. Then follow the install instructions at https://www.drupal.org/node/1419988 and set Coder with something like phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

foxtrotcharlie’s picture

Thank you so much - deleting the directory and re-installing codesniffer sorted this out. What a relief :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.