Skip to content

Commit 32e1ca2

Browse files
committed
UnusedInheritedVariablePassedToClosureSniff: Fixed fixer
1 parent 122e670 commit 32e1ca2

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

SlevomatCodingStandard/Sniffs/Functions/UnusedInheritedVariablePassedToClosureSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77
use SlevomatCodingStandard\Helpers\TokenHelper;
88
use SlevomatCodingStandard\Helpers\VariableHelper;
9+
use const T_BITWISE_AND;
910
use const T_CLOSE_PARENTHESIS;
1011
use const T_CLOSURE;
1112
use const T_COMMA;
1213
use const T_OPEN_PARENTHESIS;
1314
use const T_USE;
1415
use const T_VARIABLE;
16+
use function in_array;
1517
use function sprintf;
1618

1719
class UnusedInheritedVariablePassedToClosureSniff implements Sniff
@@ -115,7 +117,7 @@ private function checkVariableUsage(
115117
break;
116118
}
117119

118-
if ($tokens[$fixEndPointer + 1]['code'] === T_VARIABLE) {
120+
if (in_array($tokens[$fixEndPointer + 1]['code'], [T_VARIABLE, T_BITWISE_AND], true)) {
119121
break;
120122
}
121123

tests/Sniffs/Functions/UnusedInheritedVariablePassedToClosureSniffTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ public function testErrors(): void
1717
{
1818
$report = self::checkFile(__DIR__ . '/data/unusedInheritedVariablePassedToClosureErrors.php');
1919

20-
self::assertSame(5, $report->getErrorCount());
20+
self::assertSame(6, $report->getErrorCount());
2121

2222
self::assertSniffError($report, 3, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $boo passed to closure.');
2323
self::assertSniffError($report, 10, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $foo passed to closure.');
2424
self::assertSniffError($report, 17, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $doo passed to closure.');
2525
self::assertSniffError($report, 23, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $boo passed to closure.');
2626
self::assertSniffError($report, 30, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $boo passed to closure.');
27+
self::assertSniffError($report, 38, UnusedInheritedVariablePassedToClosureSniff::CODE_UNUSED_INHERITED_VARIABLE, 'Unused inherited variable $output passed to closure.');
2728

2829
self::assertAllFixedInFile($report);
2930
}

tests/Sniffs/Functions/data/unusedInheritedVariablePassedToClosureErrors.fixed.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ function ($arrays) {
3131
});
3232
}
3333
};
34+
35+
(function ($type, $buffer) use (&$successful) : void {
36+
$successful = false;
37+
})();

tests/Sniffs/Functions/data/unusedInheritedVariablePassedToClosureErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ function ($arrays) use ($boo) {
3434
});
3535
}
3636
};
37+
38+
(function ($type, $buffer) use (&$output, &$successful) : void {
39+
$successful = false;
40+
})();

0 commit comments

Comments
 (0)