Skip to content

Commit 4cca2aa

Browse files
authored
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
1 parent 11b9433 commit 4cca2aa

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Tests/VariableAnalysisSniff/fixtures/ArrowFunctionFixture.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ function staticArrowFunctionAsVariableWithUnusedInside($subject) {
8787
$arrowFunc = static fn($foo) => $subject; // unused variable $foo
8888
echo $arrowFunc('hello');
8989
}
90+
91+
function arrowFunctionAsExpressionInArgumentWithArray() {
92+
$type = do_something(fn($array, $needle) => $array[2] === $needle);
93+
echo $type;
94+
}

VariableAnalysis/Lib/Helpers.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,6 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr)
628628
public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
629629
{
630630
$tokens = $phpcsFile->getTokens();
631-
if (defined('T_FN') && $tokens[$stackPtr]['code'] === T_FN) {
632-
return [
633-
'scope_opener' => $tokens[$stackPtr]['scope_opener'],
634-
'scope_closer' => $tokens[$stackPtr]['scope_closer'],
635-
];
636-
}
637631
if ($tokens[$stackPtr]['content'] !== 'fn') {
638632
return null;
639633
}

0 commit comments

Comments
 (0)