Skip to content

UselessInheritDocComment is confused by method attributes #1233

@derrabus

Description

@derrabus

In PHP 8.0, I can insert an attribute block between a method declaration and the PHPDoc block, for example:

use ReflectionProperty;

final class MyProperty extends ReflectionProperty
{
    /**
     * {@inheritdoc}
     */
    #[SomeAttribute]
    public function getValue($object = null)
    {
        parent::getValue($object);
    }
}

If I do so, I get a CodeSniffer error like this:

FILE: /path/to/MyProperty.php
-------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------
 9 | ERROR | [x] Useless documentation comment with @inheritDoc.
   |       |     (SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment)
-------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------

If I remove the attribute, the error is gone. It seems as if the rule does not recognize that the PHPDoc block belongs to the method if an attribute block is inserted in between.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions