ikappas / vscode-phpcs

PHP CodeSniffer for Visual Studio Code
MIT License
128 stars 56 forks source link

Call to undefined method DrupalPractice\Project::register() #163

Closed jazz-it closed 4 years ago

jazz-it commented 4 years ago

I'm facing the following issue with my extension phpcs 1.0.5, whenever I open my Drupal Workspace:

phpcs: Uncaught Error: Call to undefined method DrupalPractice\Project::register() in ~/.config/composer/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1218

When I take a closer look, everything seems ok... is there something that I've missed?

$ pwd
~/.config/composer/vendor/squizlabs/php_codesniffer/src/Standards
$ ls -al
total 48
drwxr-xr-x 10 joe joe 4096 jan  13 17:11 .
drwxr-xr-x 11 joe joe 4096 apr  11  2019 ..
lrwxrwxrwx  1 joe joe   67 jan  13 17:11 Drupal -> ~/.config/composer/vendor/drupal/coder/coder_sniffer/Drupal
lrwxrwxrwx  1 joe joe   76 jan  13 17:11 DrupalPractice -> ~/.config/composer/vendor/drupal/coder/coder_sniffer/DrupalPractice/
drwxr-xr-x  5 joe joe 4096 apr  11  2019 Generic
drwxr-xr-x  4 joe joe 4096 apr  11  2019 MySource
drwxr-xr-x  5 joe joe 4096 apr  11  2019 PEAR
drwxr-xr-x  5 joe joe 4096 apr  11  2019 PSR1
drwxr-xr-x  5 joe joe 4096 apr  11  2019 PSR12
drwxr-xr-x  5 joe joe 4096 apr  11  2019 PSR2
drwxr-xr-x  5 joe joe 4096 apr  11  2019 Squiz
drwxr-xr-x  5 joe joe 4096 apr  11  2019 Zend
$ cat ~/.config/composer/vendor/drupal/coder/coder_sniffer/DrupalPractice/ruleset.xml 
<?xml version="1.0"?>
<ruleset name="DrupalPractice">
  <description>Drupal best practice checks</description>

  <!-- All Drupal code files must be UTF-8 encoded and we treat them as such. -->
  <arg name="encoding" value="utf-8"/>

  <arg name="extensions" value="php,module,inc,install,test,profile,theme,yml"/>

  <autoload>../Drupal/autoload.php</autoload>

  <rule ref="Internal.NoCodeFound">
    <!-- Empty files are fine, might be used for testing. -->
    <exclude-pattern>*</exclude-pattern>
  </rule>

  <rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable">
    <!-- Do not run this sniff on template files. -->
    <exclude-pattern>*.tpl.php</exclude-pattern>
  </rule>

  <!-- Ignore various version control directories. -->
  <exclude-pattern>*/\.git/*</exclude-pattern>
  <exclude-pattern>*/\.svn/*</exclude-pattern>
  <exclude-pattern>*/\.hg/*</exclude-pattern>
  <exclude-pattern>*/\.bzr/*</exclude-pattern>
</ruleset>
jazz-it commented 4 years ago

https://git.drupalcode.org/project/coder/blob/8.x-3.x/coder_sniffer/DrupalPractice/Project.php

This is the class identified as a sniff, which it shouldn't. How to avoid this issue?

jazz-it commented 4 years ago

Seems like a configuration issue. I accidentally forgot to register coding standards properly. The following lines helped:

composer global require drupal/coder:^8.3.1
composer global require dealerdirect/phpcodesniffer-composer-installer