@@ -77,16 +77,16 @@ public function process(File $phpcsFile, $returnPointer): void
7777
7878 $ variableName = $ tokens [$ variablePointer ]['content ' ];
7979
80- $ previousVariablePointer = $ this ->findPreviousVariablePointer ($ phpcsFile , $ returnPointer , $ variableName );
81- if ($ previousVariablePointer === null ) {
80+ if ($ this ->isStaticVariable ($ phpcsFile , $ variablePointer , $ variableName )) {
8281 return ;
8382 }
8483
85- if (!$ this ->isAssigmentToVariable ($ phpcsFile , $ previousVariablePointer )) {
84+ $ previousVariablePointer = $ this ->findPreviousVariablePointer ($ phpcsFile , $ returnPointer , $ variableName );
85+ if ($ previousVariablePointer === null ) {
8686 return ;
8787 }
8888
89- if ($ this ->isStaticVariable ($ phpcsFile , $ previousVariablePointer )) {
89+ if (! $ this ->isAssigmentToVariable ($ phpcsFile , $ previousVariablePointer )) {
9090 return ;
9191 }
9292
@@ -217,10 +217,37 @@ private function isAssigmentToVariable(File $phpcsFile, int $pointer): bool
217217 ], true );
218218 }
219219
220- private function isStaticVariable (File $ phpcsFile , int $ variablePointer ): bool
220+ private function isStaticVariable (File $ phpcsFile , int $ variablePointer, string $ variableName ): bool
221221 {
222- $ pointerBeforeVariable = TokenHelper::findPreviousEffective ($ phpcsFile , $ variablePointer - 1 );
223- return $ phpcsFile ->getTokens ()[$ pointerBeforeVariable ]['code ' ] === T_STATIC ;
222+ $ tokens = $ phpcsFile ->getTokens ();
223+
224+ $ functionPointer = null ;
225+ foreach (array_reverse ($ tokens [$ variablePointer ]['conditions ' ], true ) as $ conditionPointer => $ conditionTokenCode ) {
226+ if (in_array ($ conditionTokenCode , TokenHelper::$ functionTokenCodes , true )) {
227+ $ functionPointer = $ conditionPointer ;
228+ break ;
229+ }
230+ }
231+
232+ if ($ functionPointer === null ) {
233+ return false ;
234+ }
235+
236+ for ($ i = $ tokens [$ functionPointer ]['scope_opener ' ] + 1 ; $ i < $ variablePointer ; $ i ++) {
237+ if ($ tokens [$ i ]['code ' ] !== T_VARIABLE ) {
238+ continue ;
239+ }
240+ if ($ tokens [$ i ]['content ' ] !== $ variableName ) {
241+ continue ;
242+ }
243+
244+ $ pointerBeforeParameter = TokenHelper::findPreviousEffective ($ phpcsFile , $ i - 1 );
245+ if ($ tokens [$ pointerBeforeParameter ]['code ' ] === T_STATIC ) {
246+ return true ;
247+ }
248+ }
249+
250+ return false ;
224251 }
225252
226253 private function hasVariableVarAnnotation (File $ phpcsFile , int $ variablePointer ): bool
0 commit comments