@@ -184,6 +184,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
184184
185185 $ requiredOps = 0 ;
186186 $ foundOps = 0 ;
187+ $ foundBools = 0 ;
187188
188189 for ($ i = $ start ; $ i <= $ end ; $ i ++) {
189190 $ type = $ tokens [$ i ]['code ' ];
@@ -199,36 +200,42 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
199200 $ foundOps ++;
200201 }
201202
202- if ($ phpcsFile -> tokenizerType !== ' JS ' ) {
203- if ( $ tokens [ $ i ][ ' code ' ] === T_BOOLEAN_AND || $ tokens [ $ i ][ ' code ' ] === T_BOOLEAN_OR ) {
204- $ requiredOps ++;
203+ if ($ tokens [ $ i ][ ' code ' ] === T_TRUE || $ tokens [ $ i ][ ' code ' ] === T_FALSE ) {
204+ $ foundBools ++;
205+ }
205206
206- // When the instanceof operator is used with another operator
207- // like ===, you can get more ops than are required.
208- if ( $ foundOps > $ requiredOps ) {
209- $ foundOps = $ requiredOps ;
210- }
207+ if ( $ phpcsFile -> tokenizerType !== ' JS '
208+ && ( $ tokens [ $ i ][ ' code ' ] === T_BOOLEAN_AND
209+ || $ tokens [ $ i ][ ' code ' ] === T_BOOLEAN_OR )
210+ ) {
211+ $ requiredOps ++;
211212
212- // If we get to here and we have not found the right number of
213- // comparison operators, then we must have had an implicit
214- // true operation ie. if ($a) instead of the required
215- // if ($a === true), so let's add an error.
216- if ($ requiredOps !== $ foundOps ) {
217- $ error = 'Implicit true comparisons prohibited; use === TRUE instead ' ;
218- $ phpcsFile ->addError ($ error , $ stackPtr , 'ImplicitTrue ' );
219- $ foundOps ++;
220- }
213+ // When the instanceof operator is used with another operator
214+ // like ===, you can get more ops than are required.
215+ if ($ foundOps > $ requiredOps ) {
216+ $ foundOps = $ requiredOps ;
221217 }
222- }//end if
218+
219+ // If we get to here and we have not found the right number of
220+ // comparison operators, then we must have had an implicit
221+ // true operation i.e., if ($a) instead of the required
222+ // if ($a === true), so let's add an error.
223+ if ($ requiredOps !== $ foundOps ) {
224+ $ error = 'Implicit true comparisons prohibited; use === TRUE instead ' ;
225+ $ phpcsFile ->addError ($ error , $ stackPtr , 'ImplicitTrue ' );
226+ $ foundOps ++;
227+ }
228+ }
223229 }//end for
224230
225231 $ requiredOps ++;
226232
227- if ($ phpcsFile ->tokenizerType !== 'JS ' ) {
228- if ($ foundOps < $ requiredOps ) {
229- $ error = 'Implicit true comparisons prohibited; use === TRUE instead ' ;
230- $ phpcsFile ->addError ($ error , $ stackPtr , 'ImplicitTrue ' );
231- }
233+ if ($ phpcsFile ->tokenizerType !== 'JS '
234+ && $ foundOps < $ requiredOps
235+ && ($ requiredOps !== $ foundBools )
236+ ) {
237+ $ error = 'Implicit true comparisons prohibited; use === TRUE instead ' ;
238+ $ phpcsFile ->addError ($ error , $ stackPtr , 'ImplicitTrue ' );
232239 }
233240
234241 }//end process()
0 commit comments