@@ -43,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr)
43
43
$ tokens = $ phpcsFile ->getTokens ();
44
44
45
45
// 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 );
47
47
if ($ function !== false ) {
48
48
$ opener = $ tokens [$ function ]['parenthesis_opener ' ];
49
49
$ closer = $ tokens [$ function ]['parenthesis_closer ' ];
@@ -83,6 +83,12 @@ public function process(File $phpcsFile, $stackPtr)
83
83
*/
84
84
85
85
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
+
86
92
// Skip brackets.
87
93
if (isset ($ tokens [$ varToken ]['parenthesis_opener ' ]) === true && $ tokens [$ varToken ]['parenthesis_opener ' ] < $ varToken ) {
88
94
$ varToken = $ tokens [$ varToken ]['parenthesis_opener ' ];
@@ -94,12 +100,6 @@ public function process(File $phpcsFile, $stackPtr)
94
100
continue ;
95
101
}
96
102
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
-
103
103
if ($ tokens [$ varToken ]['code ' ] === T_VARIABLE ) {
104
104
// We found our variable.
105
105
break ;
@@ -146,6 +146,7 @@ public function process(File $phpcsFile, $stackPtr)
146
146
147
147
if ($ tokens [$ varToken ]['code ' ] === T_VARIABLE
148
148
|| $ tokens [$ varToken ]['code ' ] === T_OPEN_TAG
149
+ || $ tokens [$ varToken ]['code ' ] === T_GOTO_LABEL
149
150
|| $ tokens [$ varToken ]['code ' ] === T_INLINE_THEN
150
151
|| $ tokens [$ varToken ]['code ' ] === T_INLINE_ELSE
151
152
|| $ tokens [$ varToken ]['code ' ] === T_SEMICOLON
0 commit comments