@@ -43,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr)
4343 $ tokens = $ phpcsFile ->getTokens ();
4444
4545 // Ignore default value assignments in function definitions.
46- $ function = $ phpcsFile ->findPrevious ([T_FUNCTION , T_CLOSURE ], ($ stackPtr - 1 ), null , false , null , true );
46+ $ function = $ phpcsFile ->findPrevious ([T_FUNCTION , T_CLOSURE , T_FN ], ($ stackPtr - 1 ), null , false , null , true );
4747 if ($ function !== false ) {
4848 $ opener = $ tokens [$ function ]['parenthesis_opener ' ];
4949 $ closer = $ tokens [$ function ]['parenthesis_closer ' ];
@@ -83,6 +83,12 @@ public function process(File $phpcsFile, $stackPtr)
8383 */
8484
8585 for ($ varToken = ($ stackPtr - 1 ); $ varToken >= 0 ; $ varToken --) {
86+ if (in_array ($ tokens [$ varToken ]['code ' ], [T_SEMICOLON , T_OPEN_CURLY_BRACKET ], true ) === true ) {
87+ // We've reached the next statement, so we
88+ // didn't find a variable.
89+ return ;
90+ }
91+
8692 // Skip brackets.
8793 if (isset ($ tokens [$ varToken ]['parenthesis_opener ' ]) === true && $ tokens [$ varToken ]['parenthesis_opener ' ] < $ varToken ) {
8894 $ varToken = $ tokens [$ varToken ]['parenthesis_opener ' ];
@@ -94,12 +100,6 @@ public function process(File $phpcsFile, $stackPtr)
94100 continue ;
95101 }
96102
97- if ($ tokens [$ varToken ]['code ' ] === T_SEMICOLON ) {
98- // We've reached the next statement, so we
99- // didn't find a variable.
100- return ;
101- }
102-
103103 if ($ tokens [$ varToken ]['code ' ] === T_VARIABLE ) {
104104 // We found our variable.
105105 break ;
@@ -146,6 +146,7 @@ public function process(File $phpcsFile, $stackPtr)
146146
147147 if ($ tokens [$ varToken ]['code ' ] === T_VARIABLE
148148 || $ tokens [$ varToken ]['code ' ] === T_OPEN_TAG
149+ || $ tokens [$ varToken ]['code ' ] === T_GOTO_LABEL
149150 || $ tokens [$ varToken ]['code ' ] === T_INLINE_THEN
150151 || $ tokens [$ varToken ]['code ' ] === T_INLINE_ELSE
151152 || $ tokens [$ varToken ]['code ' ] === T_SEMICOLON
0 commit comments