When I try to run phpcs with the coder Drupal standards I get these errors: -

PHP Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found in \AppData\Roaming\Composer\vendor\drupal\coder\coder_sniffer\Drupal\Sniffs\Array\ArraySniff.php on line 24

Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found in \AppData\Roaming\Composer\vendor\drupal\coder\coder_sniffer\Drupal\Sniffs\Array\ArraySniff.php on line 24

Other phpcs standards are okay. Is there a way I need to reference back to the interface? It could be the way this is setup for Windows but I did carefully follow the install instructions.

Thanks for reading :-)

Comments

Dubs created an issue. See original summary.

klausi’s picture

Status: Active » Postponed (maintainer needs more info)

What version of phpcs do you use? phpcs --version

The interface should be included with PHPCS, so not sure what goes wrong there.

klausi’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Let me know if you have more info.

c-logemann’s picture

On some installation tests today I had the same error when I used a 3.* version of PHP CodeSniffer. But coder requires a version ">=2.7.0 <3.0" which is automatically correct when installing via composer.

szeidler’s picture

Edit: I was actually wrong. If you have PHP_CodeSniffer installed before using version 3, it will automatically load the latest coder version without the < 3.0 constraint :) You will need to remove PHP_CodeSniffer first and then install drupal/coder once again to resolve the dependencies.

kunalkursija’s picture

I was facing the same issue as @Dubs.

I resolved it by downgrading my PHPCS from 3.0 to 2.7.0.

Below mentioned is my global composer JSON.

{
    "require": {
        "drupal/console": "@stable",
        "drush/drush": "8.*",
        "squizlabs/php_codesniffer": "2.7.0",
        "drupal/coder": "^8.2"
    }
}
dubs’s picture

Thanks for the replies and so sorry for not responding sooner. You know how it is sometimes - you move on and forget you ever had an issue!

I will try what you've suggested and hope this works.

dang42’s picture

I'm still pretty much a composer noob, so when I read #6, I manually modified my composer.json file to include the "squizlabs/php_codesniffer": "2.7.0", entry and, while I knew I'd need to do something more, I had no idea what that "something" might be.

For others still at the "do what you're told without yet understanding what you're doing" stage, ensure the above code is in the json file, then run

composer global update on the command line. That's it.

Hopefully this will save someone some time...

anton-staroverov’s picture

Totally helped! Thank you so much!

agileadam’s picture

+1 for this. Thank you all.

msankhala’s picture

Even last version of 2.* series also fix this issue. Update this in ~/.composer/composer.json

"require": {
        "squizlabs/php_codesniffer": "^2.7",
}

and then run composer global update will fix this.

OR you can manually update to last stable version of 2.* series by composer global require squizlabs/php_codesniffer:2.9.1

super_romeo’s picture

This helped me:

sudo pear uninstall PHP_CodeSniffer
sudo pear install PHP_CodeSniffer-2.9.1
technikh’s picture

#12 worked for me.

michel.settembrino’s picture

glass.dimly’s picture

Fixed with #11.

Anonymous’s picture

Status: Closed (outdated) » Active

I like to re-open this issue... it no longer works with the latest version of php_codesniffer:3.2.3.

Steps to reproduce:

composer global update squizlabs/php_codesniffer
composer global update drupal/coder
phpcs --config-set installed_paths ~/.config/composer/vendor/drupal/coder/coder_sniffer
phpcs --standard=Drupal module_name/module_name.module

To workaround I have downgraded cs to 2.9.1 for now:

composer global update squizlabs/php_codesniffer:2.9.1.

kenorb’s picture

Title: PHP Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found » Support for PHP_CodeSniffer 3.x
Category: Support request » Feature request
kenorb’s picture

Title: Support for PHP_CodeSniffer 3.x » PHP Fatal error: Interface 'PHP_CodeSniffer_Sniff' not found
Category: Feature request » Support request
Status: Active » Closed (duplicate)
Related issues: +#2863898: Support PHP_CodeSniffer version 3.3.1
wendyz’s picture

The same as #17
Downgraded cs to 2.9.1 and it fixed the problem.

apolitsin’s picture

waiting for PHP_CodeSniffer-3.+ support

zach.bimson’s picture

+1 PHP_CodeSniffer-3.+ support

jimafisk’s picture

Downgrading codesniffer worked for me too. Steps on Ubuntu:
1. vim ~/.config/composer/composer.json
2. Change the line "squizlabs/php_codesniffer": "*", to "squizlabs/php_codesniffer": "2.9.1",
3. composer global update

This runs the following:

- Downgrading squizlabs/php_codesniffer (3.3.2 => 2.9.1): Downloading (100%)
- Downgrading drupal/coder (8.3.1 => 8.2.12):  Checking out 984c54a7b1

Codesniffer 3 support would be great! Thanks for all the hard work on the module :).

mialdi98’s picture

+1 PHP_CodeSniffer-3.+ support