@@ -429,17 +429,19 @@ public static function findVariableScope(File $phpcsFile, $stackPtr, $varName =
429429 $ varName = isset ($ varName ) ? $ varName : self ::normalizeVarName ($ token ['content ' ]);
430430
431431 $ enclosingScopeIndex = self ::findVariableScopeExceptArrowFunctions ($ phpcsFile , $ stackPtr );
432- $ arrowFunctionIndex = self ::getContainingArrowFunctionIndex ($ phpcsFile , $ stackPtr , $ enclosingScopeIndex );
433- $ isTokenInsideArrowFunctionBody = is_int ($ arrowFunctionIndex );
434- if ($ isTokenInsideArrowFunctionBody ) {
435- // Get the list of variables defined by the arrow function
436- // If this matches any of them, the scope is the arrow function,
437- // otherwise, it uses the enclosing scope.
438- if ($ arrowFunctionIndex ) {
439- $ variableNames = self ::getVariablesDefinedByArrowFunction ($ phpcsFile , $ arrowFunctionIndex );
440- self ::debug ('findVariableScope: looking for ' , $ varName , 'in arrow function variables ' , $ variableNames );
441- if (in_array ($ varName , $ variableNames , true )) {
442- return $ arrowFunctionIndex ;
432+ if ($ enclosingScopeIndex ) {
433+ $ arrowFunctionIndex = self ::getContainingArrowFunctionIndex ($ phpcsFile , $ stackPtr , $ enclosingScopeIndex );
434+ $ isTokenInsideArrowFunctionBody = is_int ($ arrowFunctionIndex );
435+ if ($ isTokenInsideArrowFunctionBody ) {
436+ // Get the list of variables defined by the arrow function
437+ // If this matches any of them, the scope is the arrow function,
438+ // otherwise, it uses the enclosing scope.
439+ if ($ arrowFunctionIndex ) {
440+ $ variableNames = self ::getVariablesDefinedByArrowFunction ($ phpcsFile , $ arrowFunctionIndex );
441+ self ::debug ('findVariableScope: looking for ' , $ varName , 'in arrow function variables ' , $ variableNames );
442+ if (in_array ($ varName , $ variableNames , true )) {
443+ return $ arrowFunctionIndex ;
444+ }
443445 }
444446 }
445447 }
0 commit comments