Skip to content

Commit 1504f91

Browse files
committed
Hotfix: fn arrow closure - Squiz.Scope.StaticThisUsage
Related #2523 I am not sure about this change as this is actually invalid code. We cannot use `$this` even inside closure, as then closure is not gonna be usable. The same in case of normal closure. Maybe here we should have another fix then?
1 parent 692237d commit 1504f91

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ public function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
6969
$end = $tokens[$stackPtr]['scope_closer'];
7070

7171
do {
72-
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE, T_ANON_CLASS], ($next + 1), $end);
72+
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE, T_FN, T_ANON_CLASS], ($next + 1), $end);
7373
if ($next === false) {
7474
continue;
7575
} else if ($tokens[$next]['code'] === T_CLOSURE
76+
|| $tokens[$next]['code'] === T_FN
7677
|| $tokens[$next]['code'] === T_ANON_CLASS
7778
) {
7879
$next = $tokens[$next]['scope_closer'];

src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ $b = new class()
7575
public static function myFunc() {
7676
$this->doSomething();
7777
}
78+
79+
public static function other() {
80+
return fn () => $this->name;
81+
}
7882
}

0 commit comments

Comments
 (0)