slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.39k stars 174 forks source link

TypeHintDeclarationSniff: optional nullable parameter reported as useless even if @param has description #167

Closed asprega closed 7 years ago

asprega commented 7 years ago

I am using version 2.4.4 of the coding standard, with phpcs 2.9.1.

Ruleset: <?xml version="1.0"?>

  <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
    <properties>
        <property name="enableEachParameterAndReturnInspection" value="true" />
    </properties>
</rule>

class TestClass
{

    /**
     * @param string|null $param2 Has description
     * @param string|null $param3 Has description
     */
    public function method(string $param1 = "", ?string $param2 = null, ?string $param3 = null): void
    {
    }
}

results in:

FILE: /var/www/TestClass.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 31 | ERROR | [x] Method
    |       |     \TestClass::method()
    |       |     has useless @param annotation for parameter
    |       |     $param3.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

NOTE: If I remove $param3, the same error is found for $param2. Looks like it only happens for the last parameter of the list. Not sure if related to the nullability or to the default value.

This seems related to #165 (BTW, thanks for fixing that and providing a tagged release so quickly!), probably an uncovered edge case.

kukulich commented 7 years ago

Thank you for your report.

Fixed in https://github.com/slevomat/coding-standard/commit/86281005e0f0d38365ec3362db0fb8113821ea51.

github-actions[bot] commented 4 years ago

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.