Skip to content

Commit

Permalink
UselessInheritDocCommentSniff: Fixed false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Jun 7, 2021
1 parent 77b3f1c commit 21e8f37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function array_merge;
use function in_array;
use function preg_match;
use const T_ATTRIBUTE;
use const T_DOC_COMMENT_OPEN_TAG;
use const T_DOC_COMMENT_STAR;
use const T_DOC_COMMENT_WHITESPACE;
Expand Down Expand Up @@ -52,14 +53,26 @@ public function process(File $phpcsFile, $docCommentOpenPointer): void
return;
}

$docCommentOwnerPointer = TokenHelper::findNext(
$phpcsFile,
array_merge(TokenHelper::$functionTokenCodes, TokenHelper::getTypeHintTokenCodes()),
$tokens[$docCommentOpenPointer]['comment_closer'] + 1
);
if ($docCommentOwnerPointer === null) {
return;
}
$searchPointer = $tokens[$docCommentOpenPointer]['comment_closer'] + 1;
do {
$docCommentOwnerPointer = TokenHelper::findNext(
$phpcsFile,
array_merge(TokenHelper::$functionTokenCodes, TokenHelper::getTypeHintTokenCodes(), [T_ATTRIBUTE]),
$searchPointer
);

if ($docCommentOwnerPointer === null) {
return;
}

if ($tokens[$docCommentOwnerPointer]['code'] === T_ATTRIBUTE) {
$searchPointer = $tokens[$docCommentOwnerPointer]['attribute_closer'] + 1;
continue;
}

break;

} while (true);

if (in_array($tokens[$docCommentOwnerPointer]['code'], TokenHelper::$functionTokenCodes, true)) {
$returnTypeHint = FunctionHelper::findReturnTypeHint($phpcsFile, $docCommentOwnerPointer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // lint >= 8.0

/**
*
Expand Down Expand Up @@ -59,6 +59,14 @@ public function iterableReturnType(): array
{
}

/**
* {@inheritdoc}
*/
#[SomeAttribute]
public function iterableReturnTypeWithAttribute(): array
{
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 21e8f37

Please sign in to comment.