File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -608,6 +608,17 @@ private static function getPreviousArrowFunctionIndex(File $phpcsFile, $stackPtr
608608 if ($ token ['content ' ] === 'fn ' && self ::isArrowFunction ($ phpcsFile , $ index )) {
609609 return $ index ;
610610 }
611+ // If we find a token that would close an arrow function scope before we
612+ // find a token that would open an arrow function scope, then we've found
613+ // a nested arrow function and we should ignore it, move back before THAT
614+ // arrow function's scope, and continue to search.
615+ $ arrowFunctionStartIndex = $ phpcsFile ->findPrevious ([T_FN ], $ index , $ enclosingScopeIndex );
616+ if (is_int ($ arrowFunctionStartIndex )) {
617+ $ openClose = self ::getArrowFunctionOpenClose ($ phpcsFile , $ arrowFunctionStartIndex );
618+ if ($ openClose && $ openClose ['scope_closer ' ] === $ index ) {
619+ $ index = $ openClose ['scope_opener ' ];
620+ }
621+ }
611622 }
612623 return null ;
613624 }
@@ -646,6 +657,15 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr)
646657 }
647658
648659 /**
660+ * Find the opening and closing scope positions for an arrow function if the
661+ * given position is the start of the arrow function (the `fn` keyword
662+ * token).
663+ *
664+ * Returns null if the passed token is not an arrow function keyword.
665+ *
666+ * If the token is an arrow function keyword, the scope opener is returned as
667+ * the provided position.
668+ *
649669 * @param File $phpcsFile
650670 * @param int $stackPtr
651671 *
You can’t perform that action at this time.
0 commit comments