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