@@ -181,22 +181,34 @@ public function process(File $phpcsFile, $stackPtr)
181
181
$ next = $ phpcsFile ->findNext (Tokens::$ emptyTokens , $ i , null , true );
182
182
if ($ next !== $ closeBracket && $ tokens [$ next ]['line ' ] === $ tokens [$ i ]['line ' ]) {
183
183
if (isset (Tokens::$ booleanOperators [$ tokens [$ next ]['code ' ]]) === false ) {
184
+ $ prev = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ i - 1 ), $ openBracket , true );
185
+ $ fixable = true ;
186
+ if (isset (Tokens::$ booleanOperators [$ tokens [$ prev ]['code ' ]]) === false
187
+ && $ phpcsFile ->findNext (T_WHITESPACE , ($ prev + 1 ), $ next , true ) !== false
188
+ ) {
189
+ // Condition spread over multi-lines interspersed with comments.
190
+ $ fixable = false ;
191
+ }
192
+
184
193
$ error = 'Each line in a multi-line IF statement must begin with a boolean operator ' ;
185
- $ fix = $ phpcsFile ->addFixableError ($ error , $ i , 'StartWithBoolean ' );
186
- if ($ fix === true ) {
187
- $ prev = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ i - 1 ), $ openBracket , true );
188
- if (isset (Tokens::$ booleanOperators [$ tokens [$ prev ]['code ' ]]) === true ) {
189
- $ phpcsFile ->fixer ->beginChangeset ();
190
- $ phpcsFile ->fixer ->replaceToken ($ prev , '' );
191
- $ phpcsFile ->fixer ->addContentBefore ($ next , $ tokens [$ prev ]['content ' ].' ' );
192
- $ phpcsFile ->fixer ->endChangeset ();
193
- } else {
194
- for ($ x = ($ prev + 1 ); $ x < $ next ; $ x ++) {
195
- $ phpcsFile ->fixer ->replaceToken ($ x , '' );
194
+ if ($ fixable === false ) {
195
+ $ phpcsFile ->addError ($ error , $ next , 'StartWithBoolean ' );
196
+ } else {
197
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ next , 'StartWithBoolean ' );
198
+ if ($ fix === true ) {
199
+ if (isset (Tokens::$ booleanOperators [$ tokens [$ prev ]['code ' ]]) === true ) {
200
+ $ phpcsFile ->fixer ->beginChangeset ();
201
+ $ phpcsFile ->fixer ->replaceToken ($ prev , '' );
202
+ $ phpcsFile ->fixer ->addContentBefore ($ next , $ tokens [$ prev ]['content ' ].' ' );
203
+ $ phpcsFile ->fixer ->endChangeset ();
204
+ } else {
205
+ for ($ x = ($ prev + 1 ); $ x < $ next ; $ x ++) {
206
+ $ phpcsFile ->fixer ->replaceToken ($ x , '' );
207
+ }
196
208
}
197
209
}
198
210
}
199
- }
211
+ }//end if
200
212
}//end if
201
213
202
214
$ prevLine = $ tokens [$ i ]['line ' ];
0 commit comments