Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error on a method DocBlock @param (Doctrine standard) #1421

Closed
kirilcvetkov opened this issue Aug 10, 2022 · 2 comments
Closed

Fatal error on a method DocBlock @param (Doctrine standard) #1421

kirilcvetkov opened this issue Aug 10, 2022 · 2 comments

Comments

@kirilcvetkov
Copy link

kirilcvetkov commented Aug 10, 2022

Describe the bug
Fatal error when a method has a line in DocBlock "@param $code" (Doctrine standard).

Code sample

class TestCase
{
    /**
     * @param $code
     *
     * @return bool
     */
    private function interpretStatus($code)
    {
        switch ($code) {
            case '1':
            case '2':
            case '3':
            case '4':
            case '6':
                return '1';
            case '7':
            case '9':
                return '0';
        }

        return false;
    }
}

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs --standard=Doctrine test.php
  3. See error message displayed

PHPCS output here

Fatal error: Uncaught TypeError: SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation::__construct(): Argument #5 ($contentNode) must be of type ?PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode, PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode given, called in /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 357 and defined in /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php:31
Stack trace:
#0 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(357): SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation->__construct('@param', 14, 16, '$code', Object(PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode))
#1 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\AnnotationHelper::SlevomatCodingStandard\Helpers\{closure}()
#2 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached(0, '/Users/kirilcve...', Object(Closure))
#3 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(372): SlevomatCodingStandard\Helpers\SniffLocalCache::getAndSetIfNotCached(Object(PHP_CodeSniffer\Files\LocalFile), 'annotations-9', Object(Closure))
#4 /Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php(680): SlevomatCodingStandard\Helpers\AnnotationHelper::getAnnotations(Object(PHP_CodeSniffer\Files\LocalFile), 9)
#5 /Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php(145): SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff->getReferences(Object(PHP_CodeSniffer\Files\LocalFile), 0)
#6 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 0)
#7 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#8 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(628): PHP_CodeSniffer\Files\LocalFile->process()
#9 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#10 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#11 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#12 /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/bin/phpcs(120): include('/System/Volumes...')
#13 {main}
  thrown in /System/Volumes/Data/Users/kirilcvetkov/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php on line 31

Versions (please complete the following information):

  • OS: MacOS 12.5
  • PHP: 8.0
  • PHPCS: PHP_CodeSniffer version 3.7.1 (stable) by Squiz (http://www.squiz.net)
  • Standard: Doctrine
@kukulich
Copy link
Contributor

Duplicate of #1384

@kukulich kukulich marked this as a duplicate of #1384 Aug 11, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants