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

CommentFileSizeAuthor
#2 3356337-2.patch555 bytesspokje

Comments

Spokje created an issue. See original summary.

spokje’s picture

StatusFileSize
new555 bytes
spokje’s picture

Status: Active » Needs review

Technically there's no need to bump the version of drupal/coder in any composer-file.
Unsure if we still want to do this in this issue.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

mondrake’s picture

Status: Reviewed & tested by the community » Needs work

Well, if that's a const, I guess it cannot be a @var. Remove that annotation altogether?

spokje’s picture

Status: Needs work » Reviewed & tested by the community

@mondrake Per the official documentation it is allowed:

@var

You may use the @var tag to document the Type of the following Structural Elements:

Constants, both class and global scope
Properties
Variables, both global and local scope

https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/var.html

mondrake’s picture

I 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:

longwave’s picture

The constant could be refactored away, ::class doesn'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/0kGMp

  • longwave committed 3a54df7a on 10.1.x
    Issue #3356337 by Spokje, mondrake: Fix incorrect type hint and make...

  • longwave committed dcbf6ff0 on 10.0.x
    Issue #3356337 by Spokje, mondrake: Fix incorrect type hint and make...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 10.1.x and 10.0.x, thanks!

Status: Fixed » Closed (fixed)

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