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 when a method has "@param $code" in DocBlock for Doctrine phpcs standard #3646

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

Comments

@kirilcvetkov
Copy link

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

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

Code sample

        /**
         * @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;
        }

Custom ruleset

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

Expected behavior
I'd expect to receive feedback on the sniffed file.

Versions (please complete the following information):

  • OS: [e.g., Windows 10, MacOS 10.15]
  • PHP: [e.g., 7.2, 7.4]
  • PHPCS: [e.g., 3.5.5, master]
  • Standard: [e.g., PSR2, PSR12, Squiz]

Additional context
Add any other context about the problem here.

@jrfnl
Copy link
Contributor

jrfnl commented Aug 10, 2022

@kirilcvetkov Based on the backtrace, this is an issue in the SlevomatCodingStandard, not in PHPCS. Please report it to the Slevomat repo.

@kirilcvetkov
Copy link
Author

Ah, I see. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants