Skip to content

Commit 68fe9fa

Browse files
committed
UnusedParameterSniff: Fixed false positive
1 parent e470c10 commit 68fe9fa

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

SlevomatCodingStandard/Sniffs/Functions/UnusedParameterSniff.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,16 @@ private function isParameter(File $phpcsFile, int $variablePointer): bool
129129

130130
private function isUsedInString(string $stringContent, string $variableName): bool
131131
{
132-
return preg_match('~(?<!\\\\)' . preg_quote($variableName, '~') . '\b(?!\()~', $stringContent) > 0;
132+
if (preg_match('~(?<!\\\\)' . preg_quote($variableName, '~') . '\b(?!\()~', $stringContent) > 0) {
133+
return true;
134+
}
135+
136+
$variableNameWithoutDollar = substr($variableName, 1);
137+
if (preg_match('~\$\{' . preg_quote($variableNameWithoutDollar, '~') . '\}~', $stringContent) > 0) {
138+
return true;
139+
}
140+
141+
return false;
133142
}
134143

135144
private function isUsedInCompactFunction(File $phpcsFile, int $compactFunctionPointer, string $variableName): bool

tests/Sniffs/Functions/data/unusedParameterNoErrors.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function usedParameterInAnotherScope($a)
3333
}
3434
}
3535

36-
function parameterInString($a)
36+
function parameterInString($a, $b)
3737
{
3838
echo "$a";
39+
echo "${b}";
3940
}
4041

4142
function parameterInHeredoc($a)

0 commit comments

Comments
 (0)