Skip to content

Commit

Permalink
UselessVariableSniff: Fixed false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed May 17, 2019
1 parent 307fcc2 commit f392053
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -293,7 +293,7 @@ private function hasVariableVarAnnotation(File $phpcsFile, int $variablePointer)
}

$docCommentContent = TokenHelper::getContent($phpcsFile, $tokens[$pointerBeforeVariable]['comment_opener'], $pointerBeforeVariable);
return preg_match('~@var\\s+\\S+\\s+' . preg_quote($tokens[$variablePointer]['content'], '~') . '~', $docCommentContent) !== 0;
return preg_match('~@var\\s+.+\\s+' . preg_quote($tokens[$variablePointer]['content'], '~') . '(?:\\s|$)~', $docCommentContent) !== 0;
}

private function hasAnotherAssigmentBefore(File $phpcsFile, int $variablePointer, string $variableName): bool
Expand Down
6 changes: 6 additions & 0 deletions tests/Sniffs/Variables/data/uselessVariableNoErrors.php
Expand Up @@ -60,6 +60,12 @@ function withDocComment() {
return $h;
}

function withGenericDocComment() {
/** @var array<int, string> $hh */
$hh = [];
return $hh;
}

function moreAssigments() {
$i = 'i';
$i .= 'ii';
Expand Down

0 comments on commit f392053

Please sign in to comment.