Skip to content

Commit af0c0c9

Browse files
committed
UnusedVariableSniff: Fixed false positive
1 parent 001066e commit af0c0c9

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use const T_VARIABLE;
4343
use const T_WHITESPACE;
4444
use function array_key_exists;
45+
use function count;
4546
use function in_array;
4647

4748
class UselessParenthesesSniff implements Sniff

SlevomatCodingStandard/Sniffs/Variables/UnusedVariableSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function isUsedInLoop(File $phpcsFile, int $variablePointer, string $var
304304
break;
305305
}
306306

307-
if (!in_array($conditionTokenCode, [T_FOREACH, T_DO, T_WHILE], true)) {
307+
if (!in_array($conditionTokenCode, [T_FOREACH, T_FOR, T_DO, T_WHILE], true)) {
308308
continue;
309309
}
310310

tests/Sniffs/Variables/data/unusedVariableNoErrors.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,12 @@ function ($values) {
241241
$value = 'changed';
242242
}
243243
};
244+
245+
function () {
246+
$bool = false;
247+
for ($i = 0; $i < 10; $i++) {
248+
if (!$bool) {
249+
$bool = true;
250+
}
251+
}
252+
};

0 commit comments

Comments
 (0)