@@ -261,102 +261,69 @@ public function process(File $phpcsFile, $stackPtr)
261
261
}
262
262
263
263
$ nextContent = $ phpcsFile ->findNext (Tokens::$ emptyTokens , ($ end + 1 ), null , true );
264
- if ($ nextContent === false || $ tokens [$ nextContent ]['line ' ] !== $ tokens [$ end ]['line ' ]) {
265
- // Looks for completely empty statements.
266
- $ next = $ phpcsFile ->findNext (T_WHITESPACE , ($ closer + 1 ), ($ end + 1 ), true );
267
- } else {
268
- $ next = ($ end + 1 );
269
- $ endLine = $ end ;
270
- }
271
-
272
- if ($ next !== $ end ) {
273
- if ($ nextContent === false || $ tokens [$ nextContent ]['line ' ] !== $ tokens [$ end ]['line ' ]) {
274
- // Account for a comment on the end of the line.
275
- for ($ endLine = $ end ; $ endLine < $ phpcsFile ->numTokens ; $ endLine ++) {
276
- if (isset ($ tokens [($ endLine + 1 )]) === false
277
- || $ tokens [$ endLine ]['line ' ] !== $ tokens [($ endLine + 1 )]['line ' ]
278
- ) {
279
- break ;
280
- }
281
- }
282
-
283
- if (isset (Tokens::$ commentTokens [$ tokens [$ endLine ]['code ' ]]) === false
284
- && ($ tokens [$ endLine ]['code ' ] !== T_WHITESPACE
285
- || isset (Tokens::$ commentTokens [$ tokens [($ endLine - 1 )]['code ' ]]) === false )
286
- ) {
287
- $ endLine = $ end ;
288
- }
289
- }
290
-
291
- if ($ endLine !== $ end ) {
292
- $ endToken = $ endLine ;
293
- $ addedContent = '' ;
294
- } else {
295
- $ endToken = $ end ;
296
- $ addedContent = $ phpcsFile ->eolChar ;
297
264
298
- if ($ tokens [$ end ]['code ' ] !== T_SEMICOLON
299
- && $ tokens [$ end ]['code ' ] !== T_CLOSE_CURLY_BRACKET
265
+ if ($ nextContent === false || $ tokens [$ nextContent ]['line ' ] !== $ tokens [$ end ]['line ' ]) {
266
+ // Account for a comment on the end of the line.
267
+ for ($ endLine = $ end ; $ endLine < $ phpcsFile ->numTokens ; $ endLine ++) {
268
+ if (isset ($ tokens [($ endLine + 1 )]) === false
269
+ || $ tokens [$ endLine ]['line ' ] !== $ tokens [($ endLine + 1 )]['line ' ]
300
270
) {
301
- $ phpcsFile -> fixer -> addContent ( $ end , ' ; ' ) ;
271
+ break ;
302
272
}
303
273
}
304
274
305
- $ next = $ phpcsFile ->findNext (T_WHITESPACE , ($ endToken + 1 ), null , true );
306
- if ($ next !== false
307
- && ($ tokens [$ next ]['code ' ] === T_ELSE
308
- || $ tokens [$ next ]['code ' ] === T_ELSEIF )
275
+ if (isset (Tokens::$ commentTokens [$ tokens [$ endLine ]['code ' ]]) === false
276
+ && ($ tokens [$ endLine ]['code ' ] !== T_WHITESPACE
277
+ || isset (Tokens::$ commentTokens [$ tokens [($ endLine - 1 )]['code ' ]]) === false )
309
278
) {
310
- $ phpcsFile ->fixer ->addContentBefore ($ next , '} ' );
311
- } else {
312
- $ indent = '' ;
313
- for ($ first = $ stackPtr ; $ first > 0 ; $ first --) {
314
- if ($ tokens [$ first ]['column ' ] === 1 ) {
315
- break ;
316
- }
317
- }
279
+ $ endLine = $ end ;
280
+ }
281
+ } else {
282
+ $ endLine = $ end ;
283
+ }
318
284
319
- if ($ tokens [$ first ]['code ' ] === T_WHITESPACE ) {
320
- $ indent = $ tokens [$ first ]['content ' ];
321
- } else if ($ tokens [$ first ]['code ' ] === T_INLINE_HTML
322
- || $ tokens [$ first ]['code ' ] === T_OPEN_TAG
323
- ) {
324
- $ addedContent = '' ;
325
- }
285
+ if ($ endLine !== $ end ) {
286
+ $ endToken = $ endLine ;
287
+ $ addedContent = '' ;
288
+ } else {
289
+ $ endToken = $ end ;
290
+ $ addedContent = $ phpcsFile ->eolChar ;
326
291
327
- $ addedContent .= $ indent .'} ' ;
328
- if ($ next !== false && $ tokens [$ endToken ]['code ' ] === T_COMMENT ) {
329
- $ addedContent .= $ phpcsFile ->eolChar ;
330
- }
292
+ if ($ tokens [$ end ]['code ' ] !== T_SEMICOLON
293
+ && $ tokens [$ end ]['code ' ] !== T_CLOSE_CURLY_BRACKET
294
+ ) {
295
+ $ phpcsFile ->fixer ->addContent ($ end , '; ' );
296
+ }
297
+ }
331
298
332
- $ phpcsFile ->fixer ->addContent ($ endToken , $ addedContent );
333
- }//end if
299
+ $ next = $ phpcsFile ->findNext (T_WHITESPACE , ($ endToken + 1 ), null , true );
300
+ if ($ next !== false
301
+ && ($ tokens [$ next ]['code ' ] === T_ELSE
302
+ || $ tokens [$ next ]['code ' ] === T_ELSEIF )
303
+ ) {
304
+ $ phpcsFile ->fixer ->addContentBefore ($ next , '} ' );
334
305
} else {
335
- if ($ nextContent === false || $ tokens [$ nextContent ]['line ' ] !== $ tokens [$ end ]['line ' ]) {
336
- // Account for a comment on the end of the line.
337
- for ($ endLine = $ end ; $ endLine < $ phpcsFile ->numTokens ; $ endLine ++) {
338
- if (isset ($ tokens [($ endLine + 1 )]) === false
339
- || $ tokens [$ endLine ]['line ' ] !== $ tokens [($ endLine + 1 )]['line ' ]
340
- ) {
341
- break ;
342
- }
306
+ $ indent = '' ;
307
+ for ($ first = $ stackPtr ; $ first > 0 ; $ first --) {
308
+ if ($ tokens [$ first ]['column ' ] === 1 ) {
309
+ break ;
343
310
}
311
+ }
344
312
345
- if ($ tokens [$ endLine ]['code ' ] !== T_COMMENT
346
- && ( $ tokens [$ endLine ]['code ' ] !== T_WHITESPACE
347
- || $ tokens [( $ endLine - 1 ) ]['code ' ] !== T_COMMENT )
348
- ) {
349
- $ endLine = $ end ;
350
- }
313
+ if ($ tokens [$ first ]['code ' ] === T_WHITESPACE ) {
314
+ $ indent = $ tokens [$ first ]['content ' ];
315
+ } else if ( $ tokens [$ first ]['code ' ] === T_INLINE_HTML
316
+ || $ tokens [ $ first ][ ' code ' ] === T_OPEN_TAG
317
+ ) {
318
+ $ addedContent = '' ;
351
319
}
352
320
353
- if ($ endLine !== $ end ) {
354
- $ phpcsFile ->fixer ->replaceToken ($ end , '' );
355
- $ phpcsFile ->fixer ->addNewlineBefore ($ endLine );
356
- $ phpcsFile ->fixer ->addContent ($ endLine , '} ' );
357
- } else {
358
- $ phpcsFile ->fixer ->replaceToken ($ end , '} ' );
321
+ $ addedContent .= $ indent .'} ' ;
322
+ if ($ next !== false && $ tokens [$ endToken ]['code ' ] === T_COMMENT ) {
323
+ $ addedContent .= $ phpcsFile ->eolChar ;
359
324
}
325
+
326
+ $ phpcsFile ->fixer ->addContent ($ endToken , $ addedContent );
360
327
}//end if
361
328
362
329
$ phpcsFile ->fixer ->endChangeset ();
0 commit comments