Skip to content

Commit

Permalink
UnusedVariableSniff: Fixed false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 16, 2020
1 parent 8ef56e0 commit 3c5fc9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SlevomatCodingStandard/Helpers/VariableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function isUsedInScopeInString(File $phpcsFile, string $variableNa
}

$variableNameWithoutDollar = substr($variableName, 1);
return preg_match('~\$\{' . preg_quote($variableNameWithoutDollar, '~') . '\}~', $stringContent) !== 0;
return preg_match('~\$\{' . preg_quote($variableNameWithoutDollar, '~') . '(<=\}|\b)~', $stringContent) !== 0;
}

private static function isUsedInScopeInternal(
Expand Down
5 changes: 5 additions & 0 deletions tests/Sniffs/Variables/data/unusedVariableNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ function () {
echo "${a}";
};

function () {
$a = '';
echo "${a[0]}";
};

function () {
$a = '';
echo "$a()";
Expand Down

0 comments on commit 3c5fc9b

Please sign in to comment.