Skip to content

Commit 5d77d35

Browse files
committed
StaticClosureSniff: Fixed false positive
1 parent fb3ecc0 commit 5d77d35

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

SlevomatCodingStandard/Sniffs/Functions/StaticClosureSniff.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77
use SlevomatCodingStandard\Helpers\TokenHelper;
88
use const T_CLOSURE;
9+
use const T_OPEN_PARENTHESIS;
910
use const T_PARENT;
1011
use const T_STATIC;
12+
use const T_STRING;
1113
use const T_VARIABLE;
1214

1315
class StaticClosureSniff implements Sniff
@@ -39,6 +41,16 @@ public function process(File $phpcsFile, $closurePointer): void
3941
return;
4042
}
4143

44+
if ($tokens[$previousPointer]['code'] === T_OPEN_PARENTHESIS) {
45+
$pointerBeforeParenthesis = TokenHelper::findPreviousEffective($phpcsFile, $previousPointer - 1);
46+
if (
47+
$tokens[$pointerBeforeParenthesis]['code'] === T_STRING
48+
&& $tokens[$pointerBeforeParenthesis]['content'] === 'bind'
49+
) {
50+
return;
51+
}
52+
}
53+
4254
$thisPointer = TokenHelper::findNextContent($phpcsFile, T_VARIABLE, '$this', $tokens[$closurePointer]['scope_opener'] + 1, $tokens[$closurePointer]['scope_closer']);
4355
if ($thisPointer !== null) {
4456
return;

tests/Sniffs/Functions/data/staticClosureNoErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ public function withParent()
2929
}
3030

3131
}
32+
33+
Closure::bind(function ($instance, $value) {
34+
$instance->property = $value;
35+
}, $instance, $instance);

0 commit comments

Comments
 (0)