From 4cca2aaf7f12a24c5a434e7a72c22b40e1346c79 Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Thu, 30 Mar 2023 19:12:07 -0400 Subject: [PATCH] Use custom logic for finding arrow function scope (#296) * Add test for arrow function as argument * Do not rely on phpcs to find scope for arrow functions --- .../VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php | 5 +++++ VariableAnalysis/Lib/Helpers.php | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Tests/VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php b/Tests/VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php index 9873fff..f81518d 100644 --- a/Tests/VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php +++ b/Tests/VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php @@ -87,3 +87,8 @@ function staticArrowFunctionAsVariableWithUnusedInside($subject) { $arrowFunc = static fn($foo) => $subject; // unused variable $foo echo $arrowFunc('hello'); } + +function arrowFunctionAsExpressionInArgumentWithArray() { + $type = do_something(fn($array, $needle) => $array[2] === $needle); + echo $type; +} diff --git a/VariableAnalysis/Lib/Helpers.php b/VariableAnalysis/Lib/Helpers.php index 1324eab..5e961e7 100644 --- a/VariableAnalysis/Lib/Helpers.php +++ b/VariableAnalysis/Lib/Helpers.php @@ -628,12 +628,6 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr) public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (defined('T_FN') && $tokens[$stackPtr]['code'] === T_FN) { - return [ - 'scope_opener' => $tokens[$stackPtr]['scope_opener'], - 'scope_closer' => $tokens[$stackPtr]['scope_closer'], - ]; - } if ($tokens[$stackPtr]['content'] !== 'fn') { return null; }