@@ -124,18 +124,50 @@ private function containsOperators(File $phpcsFile, int $parenthesisOpenerPointe
124124 {
125125 $ tokens = $ phpcsFile ->getTokens ();
126126
127- if (TokenHelper::findNext ($ phpcsFile , [T_PLUS , T_MINUS , T_STRING_CONCAT ], $ parenthesisOpenerPointer + 1 , $ tokens [$ parenthesisOpenerPointer ]['parenthesis_closer ' ]) === null ) {
127+ $ operators = [T_PLUS , T_MINUS , T_MULTIPLY , T_DIVIDE , T_STRING_CONCAT ];
128+
129+ $ operatorsPointers = TokenHelper::findNextAll ($ phpcsFile , $ operators , $ parenthesisOpenerPointer + 1 , $ tokens [$ parenthesisOpenerPointer ]['parenthesis_closer ' ]);
130+ if (count ($ operatorsPointers ) === 0 ) {
128131 return false ;
129132 }
130133
134+ $ containsPlusOrMinus = false ;
135+ $ containsMultiplyOrDivide = false ;
136+ $ containsStringConcat = false ;
137+ foreach ($ operatorsPointers as $ operatorsPointer ) {
138+ if (in_array ($ tokens [$ operatorsPointer ]['code ' ], [T_PLUS , T_MINUS ], true )) {
139+ $ containsPlusOrMinus = true ;
140+ } elseif (in_array ($ tokens [$ operatorsPointer ]['code ' ], [T_MULTIPLY , T_DIVIDE ], true )) {
141+ $ containsMultiplyOrDivide = true ;
142+ } else {
143+ $ containsStringConcat = true ;
144+ }
145+ }
146+
131147 $ pointerAfterParenthesis = TokenHelper::findNextEffective ($ phpcsFile , $ tokens [$ parenthesisOpenerPointer ]['parenthesis_closer ' ] + 1 );
132- if (in_array ($ tokens [$ pointerAfterParenthesis ]['code ' ], [T_MULTIPLY , T_DIVIDE , T_STRING_CONCAT ], true )) {
133- return true ;
148+ if (in_array ($ tokens [$ pointerAfterParenthesis ]['code ' ], $ operators , true )) {
149+ if ($ containsPlusOrMinus && in_array ($ tokens [$ pointerAfterParenthesis ]['code ' ], [T_MULTIPLY , T_DIVIDE ], true )) {
150+ return true ;
151+ }
152+ if ($ containsMultiplyOrDivide && in_array ($ tokens [$ pointerAfterParenthesis ]['code ' ], [T_PLUS , T_MINUS ], true )) {
153+ return true ;
154+ }
155+ if ($ containsStringConcat || $ tokens [$ pointerAfterParenthesis ]['code ' ] === T_STRING_CONCAT ) {
156+ return true ;
157+ }
134158 }
135159
136160 $ pointerBeforeParenthesis = TokenHelper::findPreviousEffective ($ phpcsFile , $ parenthesisOpenerPointer - 1 );
137- if (in_array ($ tokens [$ pointerBeforeParenthesis ]['code ' ], [T_MULTIPLY , T_DIVIDE , T_STRING_CONCAT ], true )) {
138- return true ;
161+ if (in_array ($ tokens [$ pointerBeforeParenthesis ]['code ' ], $ operators , true )) {
162+ if ($ containsPlusOrMinus && in_array ($ tokens [$ pointerBeforeParenthesis ]['code ' ], [T_MULTIPLY , T_DIVIDE ], true )) {
163+ return true ;
164+ }
165+ if ($ containsMultiplyOrDivide && in_array ($ tokens [$ pointerBeforeParenthesis ]['code ' ], [T_PLUS , T_MINUS ], true )) {
166+ return true ;
167+ }
168+ if ($ containsStringConcat || $ tokens [$ pointerBeforeParenthesis ]['code ' ] === T_STRING_CONCAT ) {
169+ return true ;
170+ }
139171 }
140172
141173 return false ;
0 commit comments