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

TypeError with Slevomat Coding Standard version 8.11.1 and PHP 8.2 #1566

Closed
dealense7 opened this issue May 1, 2023 · 9 comments
Closed

Comments

@dealense7
Copy link

I am using the Slevomat Coding Standard version 8.11.1 with PHP 8.2 and I am encountering a TypeError. Specifically, I receive the following error message:

"
..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 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 359 and defined in /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/TypeAliasAnnotation.php:21
"

I have reviewed the code that calls the constructor method for the TypeAliasAnnotation class and confirmed that the fifth argument, $contentNode, is of the correct type ?PHPStan\PhpDocParser\Ast\PhpDoc\TypeAliasTagValueNode

@kukulich
Copy link
Contributor

kukulich commented May 1, 2023

Can you please post yout code that throws this error?

@dealense7
Copy link
Author

Can you please post yout code that throws this error?

I added this in phpcs.xml

<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>

and run this

vendor/bin/phpcs --standard=laravel.phpcs.xml -spn --encoding=utf-8 --report-width=150 --colors --parallel=16 app/ config/ tests/

@kukulich
Copy link
Contributor

kukulich commented May 1, 2023

Try please verbose mode in PHPCS and find the file (and then the specific code) that throws the error.

@dealense7
Copy link
Author

@kukulich

File: laravel.phpcs.xml

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="laravel-php-code-style" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <description>Laravel PHP Code Style preset</description>

    <rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>

    <exclude-pattern>*\.blade\.php$</exclude-pattern>
</ruleset>

Command: vendor/bin/phpcs -v --standard=laravel.phpcs.xml -spn --encoding=utf-8 --report-width=150 --colors --parallel=16 app/ config/ tests/

Error:

    Changing into directory /home/houston/Documents/project/app/Http/Requests/Web/Company
    Processing CompanyQueueAddRequest.php [PHP => 126 tokens in 26 lines]... DONE in 1ms (0 errors, 0 warnings)
    Processing CompanyCreateRequest.php [PHP => 359 tokens in 76 lines]... DONE in 24ms (0 errors, 0 warnings)
    Processing CompanySaveRequest.php [PHP => 263 tokens in 55 lines]... DONE in 3ms (0 errors, 0 warnings)
    Processing CompanyConnectionSaveRequest.php [PHP => 153 tokens in 27 lines]... DONE in 2ms (0 errors, 0 warnings)
    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 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 359 and defined in /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/TypeAliasAnnotation.php:21
    Stack trace:
    #0 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(359): SlevomatCodingStandard\Helpers\Annotation\TypeAliasAnnotation->__construct()
    #1 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\AnnotationHelper::SlevomatCodingStandard\Helpers\{closure}()
    #2 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached()
    #3 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(250): SlevomatCodingStandard\Helpers\SniffLocalCache::getAndSetIfNotCached()
    #4 /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullTypeHintOnLastPositionSniff.php(39): SlevomatCodingStandard\Helpers\AnnotationHelper::getAnnotations()
    #5 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): SlevomatCodingStandard\Sniffs\TypeHints\NullTypeHintOnLastPositionSniff->process()
    #6 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
    #7 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/src/Runner.php(632): PHP_CodeSniffer\Files\LocalFile->process()
    #8 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/src/Runner.php(504): PHP_CodeSniffer\Runner->processFile()
    #9 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/src/Runner.php(116): PHP_CodeSniffer\Runner->run()
    #10 /home/houston/Documents/project/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
    #11 /home/houston/Documents/project/vendor/bin/phpcs(117): include('...')
    #12 {main}
    thrown in /home/houston/Documents/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/TypeAliasAnnotation.php on line 21

    ```

@kukulich
Copy link
Contributor

kukulich commented May 2, 2023

@dealense7 I need the specific doc comment in your sources that throws this error.

@dealense7
Copy link
Author

@kukulich

No Error:

<?php

declare(strict_types=1);

return [

    /** @var array */
    'exclude_groups' => [],
];

Error:

<?php

declare(strict_types=1);

return [

    /** @type array */
    'exclude_groups' => [],
];

@kukulich
Copy link
Contributor

kukulich commented May 2, 2023

It the annotation @type somehow official? It's not mention here: https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/index.html

@dealense7
Copy link
Author

@github-actions
Copy link

github-actions bot commented Jun 3, 2023

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 Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants