@@ -94,35 +94,29 @@ public function process(File $phpcsFile, $stackPtr)
94
94
}
95
95
}//end if
96
96
97
- // Check if this token is actually part of a one-line IF or ELSE statement.
98
- for ($ i = ($ stackPtr - 1 ); $ i > 0 ; $ i --) {
99
- if ($ tokens [$ i ]['code ' ] === T_CLOSE_PARENTHESIS ) {
100
- $ i = $ tokens [$ i ]['parenthesis_opener ' ];
101
- continue ;
102
- } else if (isset (Tokens::$ emptyTokens [$ tokens [$ i ]['code ' ]]) === true ) {
103
- continue ;
104
- }
105
-
106
- break ;
107
- }
108
-
109
- if ($ tokens [$ i ]['code ' ] === T_IF
110
- || $ tokens [$ i ]['code ' ] === T_ELSE
111
- || $ tokens [$ i ]['code ' ] === T_ELSEIF
97
+ // This token may be part of an inline condition.
98
+ // If we find a closing parenthesis that belongs to a condition,
99
+ // or an "else", we should ignore this token.
100
+ if ($ tokens [$ prev ]['code ' ] === T_ELSE
101
+ || (isset ($ tokens [$ prev ]['parenthesis_owner ' ]) === true
102
+ && ($ tokens [$ tokens [$ prev ]['parenthesis_owner ' ]]['code ' ] === T_IF
103
+ || $ tokens [$ tokens [$ prev ]['parenthesis_owner ' ]]['code ' ] === T_ELSEIF ))
112
104
) {
113
105
return ;
114
106
}
115
107
116
108
if ($ tokens [$ stackPtr ]['code ' ] === T_RETURN ) {
117
- $ next = $ phpcsFile ->findNext (T_WHITESPACE , ($ stackPtr + 1 ), null , true );
109
+ $ next = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , ($ stackPtr + 1 ), null , true );
118
110
if ($ tokens [$ next ]['code ' ] === T_SEMICOLON ) {
119
- $ next = $ phpcsFile ->findNext (T_WHITESPACE , ($ next + 1 ), null , true );
111
+ $ next = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , ($ next + 1 ), null , true );
120
112
if ($ tokens [$ next ]['code ' ] === T_CLOSE_CURLY_BRACKET ) {
121
113
// If this is the closing brace of a function
122
114
// then this return statement doesn't return anything
123
115
// and is not required anyway.
124
116
$ owner = $ tokens [$ next ]['scope_condition ' ];
125
- if ($ tokens [$ owner ]['code ' ] === T_FUNCTION ) {
117
+ if ($ tokens [$ owner ]['code ' ] === T_FUNCTION
118
+ || $ tokens [$ owner ]['code ' ] === T_CLOSURE
119
+ ) {
126
120
$ warning = 'Empty return statement not required here ' ;
127
121
$ phpcsFile ->addWarning ($ warning , $ stackPtr , 'ReturnNotRequired ' );
128
122
return ;
@@ -174,21 +168,6 @@ public function process(File $phpcsFile, $stackPtr)
174
168
}//end if
175
169
}//end if
176
170
177
- // This token may be part of an inline condition.
178
- // If we find a closing parenthesis that belongs to a condition
179
- // we should ignore this token.
180
- if (isset ($ tokens [$ prev ]['parenthesis_owner ' ]) === true ) {
181
- $ owner = $ tokens [$ prev ]['parenthesis_owner ' ];
182
- $ ignore = [
183
- T_IF => true ,
184
- T_ELSE => true ,
185
- T_ELSEIF => true ,
186
- ];
187
- if (isset ($ ignore [$ tokens [$ owner ]['code ' ]]) === true ) {
188
- return ;
189
- }
190
- }
191
-
192
171
$ ourConditions = array_keys ($ tokens [$ stackPtr ]['conditions ' ]);
193
172
194
173
if (empty ($ ourConditions ) === false ) {
0 commit comments