From 1504f9170e704ae727568eba6acf907620271e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Tue, 26 Nov 2019 20:31:55 +0000 Subject: [PATCH] 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? --- src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php | 3 ++- src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php b/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php index 032d880cd3..ca99727aa1 100644 --- a/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php +++ b/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php @@ -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']; diff --git a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc index 6684aa1fa6..87f022c85a 100644 --- a/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc +++ b/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc @@ -75,4 +75,8 @@ $b = new class() public static function myFunc() { $this->doSomething(); } + + public static function other() { + return fn () => $this->name; + } }