Skip to content

Commit

Permalink
Hotfix: fn arrow closure - Squiz.Scope.StaticThisUsage
Browse files Browse the repository at this point in the history
Related squizlabs#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?
  • Loading branch information
michalbundyra committed Jan 6, 2020
1 parent 692237d commit 1504f91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ public function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
$end = $tokens[$stackPtr]['scope_closer'];

do {
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE, T_ANON_CLASS], ($next + 1), $end);
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE, T_FN, T_ANON_CLASS], ($next + 1), $end);
if ($next === false) {
continue;
} else if ($tokens[$next]['code'] === T_CLOSURE
|| $tokens[$next]['code'] === T_FN
|| $tokens[$next]['code'] === T_ANON_CLASS
) {
$next = $tokens[$next]['scope_closer'];
Expand Down
4 changes: 4 additions & 0 deletions src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ $b = new class()
public static function myFunc() {
$this->doSomething();
}

public static function other() {
return fn () => $this->name;
}
}

0 comments on commit 1504f91

Please sign in to comment.