Problem/Motivation

As reported in #3116405: Warnings generated when using an optimized autoload file with Composer 1.10 / Composer 2
Coder needs to fix composer classmap somehow for newer versions of composer

Deprecation Notice: Class DrupalPractice\Sniffs\CodeAnalysis\VariableAnalysisSniff located in ./vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///home/andypost/www/core8/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:185

Release notes said
https://github.com/composer/composer/releases/tag/1.10.0

https://github.com/composer/composer/releases/tag/1.10.0-RC

Deprecated: Added a warning when class names are being loaded by a PSR-4 or PSR-0 rule only due to classmap optimization, but would not otherwise be autoloadable. Composer 2.0 will stop autoloading these classes so make sure you fix your autoload configs.

Proposed resolution

To find out

Remaining tasks

tbd

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

tbd

Comments

andypost created an issue. See original summary.

andypost’s picture

Issue summary: View changes
Arkener’s picture

This issue seems to have been fixed here on the development branch. Switching to psr-4 autoloading will result in 2 deprecation warnings:

Deprecation Notice: Class Drupal\Example\Something\TestCase located in ./coder_sniffer/Drupal/Test/Commenting/FileCommentUnitTest.12.inc does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185
Deprecation Notice: Class Drupal\random\bunny_hat\long\namingspace\wtf\still\going\strong\LongNamespace located in ./coder_sniffer/Drupal/Test/good/drupal8/LongNamespace.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185

These files are only used to test sniffs and don't have to be autoloaded.

andypost’s picture

klausi’s picture

A potential fix would be to move the test cases into a dedicated tests folder outside of coder_sniffer. PHPCS has moved their tests for example https://github.com/squizlabs/PHP_CodeSniffer/tree/master/tests

andypost’s picture

joelpittet’s picture

I saw a wall of "Deprecation Notice" today in composer, a good chunk of it was this project but not the only one. date_recur and drush are also in the orange wall.

I'll be keen to see what the solution is here to see if I can help those other projects fix it as well.

andypost’s picture

New release https://github.com/composer/composer/releases/tag/1.10.1

Btw I also recall issue with theme info files from tests

fgm’s picture

Beyond coder_sniffer, some core and contrib classes have the same issue:

  • Core: Symfony\Cmf\Component\Routing\Tests\Mapper\FieldMapEnhancerTest
  • Core: Symfony\Cmf\Component\Routing\PagedRouteCollectionTest
  • Core: Symfony\Cmf\Component\Routing\LazyRouteCollectionTest
  • Core: EasyRdf_Serialiser_JsonLd
  • Core: EasyRdf_Parser_JsonLd
  • Diff: Class HTMLPurifier_Language_en_x_test
Dane Powell’s picture

Priority: Normal » Major

Note that Composer 2 will be released in a few weeks, at which point these won't just be deprecation warnings any more, they will be full errors. I think that warrants a higher priority.

klausi’s picture

Title: Support composer 1.10 and onwards » Prevent composer 1.10 autoload warnings by moving the test files

Started moving the tests outside the autoload directory at https://github.com/pfrenssen/coder/pull/107

klausi’s picture

Status: Active » Needs review
Arkener’s picture

Status: Needs review » Reviewed & tested by the community

Checked and left a comment on https://github.com/pfrenssen/coder/pull/107, everything seems to be good to go!

  • klausi authored bfd3005 on 8.x-3.x
    fix(composer): Prevent composer autoload warnings by moving the tests...
klausi’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Thanks a lot for reviewing Arkener, merged that!

Tested this on a Drupal 8 client project where I installed the most recent Coder dev branch commit and the 2 yellow Composer warnings for Coder are gone.

Downgrading this to normal since these are only Composer warning messages. It does not matter to us if Composer 2 will not autoload Coder test files that should never be autoloaded anyway.

I want to wait for a couple more weeks before I make the next Coder release. Let me know if there is any urgent reason to make a release earlier.

Status: Fixed » Closed (fixed)

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