@@ -94,35 +94,29 @@ public function process(File $phpcsFile, $stackPtr)
9494 }
9595 }//end if
9696
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 ))
112104 ) {
113105 return ;
114106 }
115107
116108 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 );
118110 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 );
120112 if ($ tokens [$ next ]['code ' ] === T_CLOSE_CURLY_BRACKET ) {
121113 // If this is the closing brace of a function
122114 // then this return statement doesn't return anything
123115 // and is not required anyway.
124116 $ 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+ ) {
126120 $ warning = 'Empty return statement not required here ' ;
127121 $ phpcsFile ->addWarning ($ warning , $ stackPtr , 'ReturnNotRequired ' );
128122 return ;
@@ -174,21 +168,6 @@ public function process(File $phpcsFile, $stackPtr)
174168 }//end if
175169 }//end if
176170
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-
192171 $ ourConditions = array_keys ($ tokens [$ stackPtr ]['conditions ' ]);
193172
194173 if (empty ($ ourConditions ) === false ) {
0 commit comments