Problem/Motivation
Currently our daily "updated deps" QA job fails on 10.0.x and 10.1.x with a nice:
PHP Fatal error: Uncaught TypeError: SlevomatCodingStandard\Helpers\Annotation\TypeAliasAnnotation::__construct(): Argument #5 ($contentNode) must be of type ?PHPStan\PhpDocParser\Ast\PhpDoc\TypeAliasTagValueNode, PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode given, called in /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 359 and defined in /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/TypeAliasAnnotation.php:21
Stack trace:
#0 /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(359): SlevomatCodingStandard\Helpers\Annotation\TypeAliasAnnotation->__construct('@type', 81, 83, 'string', Object(PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode))
#1 /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\AnnotationHelper::SlevomatCodingStandard\Helpers\{closure}()
#2 /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached(0, '/var/www/html/c...', Object(Closure))
#3 /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(374): SlevomatCodingStandard\Helpers\SniffLocalCache::getAndSetIfNotCached(Object(PHP_CodeSniffer\Files\LocalFile), 'annotations-60', Object(Closure))
#4 /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/ForbiddenAnnotationsSniff.php(49): SlevomatCodingStandard\Helpers\AnnotationHelper::getAnnotations(Object(PHP_CodeSniffer\Files\LocalFile), 60)
#5 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): SlevomatCodingStandard\Sniffs\Commenting\ForbiddenAnnotationsSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 60)
#6 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#7 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(632): PHP_CodeSniffer\Files\LocalFile->process()
#8 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(504): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#9 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(116): PHP_CodeSniffer\Runner->run()
#10 /var/www/html/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#11 /var/www/html/vendor/bin/phpcs(120): include('/var/www/html/v...')
#12 {main}
thrown in /var/www/html/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/TypeAliasAnnotation.php on line 21
PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: One or more child processes failed to run in /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php:546
Stack trace:
#0 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(116): PHP_CodeSniffer\Runner->run()
#1 /var/www/html/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#2 /var/www/html/vendor/bin/phpcs(120): include('/var/www/html/v...')
#3 {main}
thrown in /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php on line 546
(See https://www.drupal.org/node/3060/qa)
Steps to reproduce
See https://www.drupal.org/node/3060/qa and notice the failures on both updated deps jobs for 10.0.x and 10.1.x
After some research it turns out that the update of drupal/coder which updates (amongst other dependencies) slevomat/coding-standard in combination with a incorrect type hint is the root cause.
Run:
- composer update drupal/coder -W
- vendor/bin/phpcs -ps --parallel=$(nproc) --standard="./core/phpcs.xml.dist" core/lib/Drupal/Core/Template/DebugExtension.php -vvv\
- CLUNK!
Proposed resolution
- Fix incorrect type hint in core/lib/Drupal/Core/Template/DebugExtension.php
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
spokjeComment #3
spokjeTechnically there's no need to bump the version of
drupal/coderin anycomposer-file.Unsure if we still want to do this in this issue.
Comment #4
longwaveI don't see the need to bump Coder if we are going to fix the source of the issue instead. Added an updated deps test run to check that the fix works, assuming it does this is RTBC.
Comment #5
mondrakeWell, if that's a
const, I guess it cannot be a@var. Remove that annotation altogether?Comment #6
spokje@mondrake Per the official documentation it is allowed:
https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/var.html
Comment #7
mondrakeI see... Never seen that used in Drupal tho. Drupal's coding standards don't mention anything. But they're outdated, anyway, do not mention visibility either. So :shrug:
Comment #8
longwaveThe constant could be refactored away,
::classdoesn't care if the class doesn't exist and it will evaluate to a string anyway, but that can be done in another issue: https://3v4l.org/0kGMpComment #11
longwaveCommitted and pushed to 10.1.x and 10.0.x, thanks!