Problem/Motivation

After updating drupal/coder from v8.3.1 to v8.3.2 we can no longer run PHPCS and receive the following error.

# vendor/bin/phpcs .

Fatal error: Cannot declare class Drupal\Sniffs\InfoFiles\ClassFilesSniff, because the name is already in use in ./vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php on line 23

Rolling back to drupal/coder:8.3.1 resolves the issue.

Here are the relevant packages and versions in use for our project. I've also already verified that I have no global installation for the relevant packages. All installs are local to my project.

drupal/core 8.6.13
drupal/coder 8.3.2
squizlabs/php_codesniffer  3.4.2
dealerdirect/phpcodesniffer-composer-installer v0.4.4

Proposed resolution

Find and fix the namespace clash for class Drupal\Sniffs\InfoFiles\ClassFilesSniff

Remaining tasks

Add some tests?

Release notes snippet

Comments

chOP created an issue. See original summary.

vladimiraus’s picture

+1. Reverting back to 8.3.1 can be a temporary fix.

evgeny.chernyavskiy’s picture

Confirming this issue cropped up after upgrading to 8.3.2. Looks like the class in question is autoloaded, and then loaded explicitly yet again in vendor/drupal/coder/coder_sniffer/DrupalPractice/ruleset.xml. Patch attached.

klausi’s picture

Hm, I added a test case explicitly for DrupalPractice calls ... can you create this as pull request at https://github.com/pfrenssen/coder ? Then we can see the automated test results.

evgeny.chernyavskiy’s picture

klausi’s picture

Status: Active » Fixed

Thanks, I tried a couple of thing to reproduce the problem I had with ClassFilesSniff but did not run into the problem anymore, so this should be fine.

Thanks!

klausi’s picture

@chOP and @VladimirAus: can you test the 8.x-3.x dev version of Coder now and let me know if this fixes your problem? Then I can release Coder 8.3.3.

chop’s picture

Status: Fixed » Active

@klausi,
Confirmed that this commit has fixed the issue for me when using Drupal and DrupalPractice standards.

Test steps performed:

# composer require "drupal/coder:dev-8.x-3.x as 8.3.3"
# cd vendor/drupal/coder/
# git pull --ff-only
# git log -1
commit a33d3388fb2e1d94bd2aee36a8ff79186e9d8f43 (HEAD -> 8.x-3.x, origin/8.x-3.x, composer/8.x-3.x)
Author: Evgeny Chernyavskiy <evgeny.chernyavskiy@gmail.com>
Date:   Tue Apr 16 14:56:06 2019 -0400

    fix(autoload): Fix PHP Fatal error: ClassFilesSniff namespace clash (#3048092)

# cd -
# vendor/bin/phpcs .
........................................................ 56 / 56 (100%)


Time: 1.06 secs; Memory: 12MB

I happy to report that the fix seems to work for me. Thanks for jumping on this quickly.

chop’s picture

Status: Active » Fixed

Why did the status change back to active?
Setting it to fixed again.

klausi’s picture

Thanks, released as Coder 8.3.3!

vladimiraus’s picture

Thanks @klausi and @chOP
Works for me.

jonathan1055’s picture

I had previously raised #3049433: Coding standards not running on d.o. - upgrade to coder 8.3.4 which looks like the same problem? Maybe I did that on the wrong issue queue as got no response. I did search for the issue but maybe not in the Coder queue.

Status: Fixed » Closed (fixed)

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