@@ -62,6 +62,14 @@ public function tokenizeString($string, $eolChar='\n')
62
62
for ($ stackPtr = 0 ; $ stackPtr < $ numTokens ; $ stackPtr ++) {
63
63
$ token = $ tokens [$ stackPtr ];
64
64
65
+ // CSS files don't have lists or break tags, so convert these to
66
+ // standard strings early so they can be converted into T_STYLE
67
+ // tokens and joined with other strings if needed.
68
+ if ($ token ['code ' ] === T_BREAK || $ token ['code ' ] === T_LIST ) {
69
+ $ token ['type ' ] = 'T_STRING ' ;
70
+ $ token ['code ' ] = T_STRING ;
71
+ }
72
+
65
73
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
66
74
$ type = $ token ['type ' ];
67
75
$ content = str_replace ($ eolChar , '\n ' , $ token ['content ' ]);
@@ -355,159 +363,15 @@ public function tokenizeString($string, $eolChar='\n')
355
363
/**
356
364
* Performs additional processing after main tokenizing.
357
365
*
358
- * This additional processing converts T_LIST tokens to T_STRING
359
- * because there are no list constructs in CSS and list-* styles
360
- * look like lists to the PHP tokenizer.
361
- *
362
366
* @param array &$tokens The array of tokens to process.
363
367
* @param string $eolChar The EOL character to use for splitting strings.
364
368
*
365
369
* @return void
366
370
*/
367
371
public function processAdditional (&$ tokens , $ eolChar )
368
372
{
369
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
370
- echo "\t*** START ADDITIONAL CSS PROCESSING *** " .PHP_EOL ;
371
- }
372
-
373
- $ numTokens = (count ($ tokens ) - 1 );
374
- $ changeMade = false ;
375
-
376
- for ($ i = 0 ; $ i < $ numTokens ; $ i ++) {
377
- if ($ tokens [($ i + 1 )]['code ' ] !== T_STYLE ) {
378
- continue ;
379
- }
380
-
381
- $ style = ($ i + 1 );
382
-
383
- if ($ tokens [$ i ]['code ' ] === T_LIST ) {
384
- $ tokens [$ style ]['content ' ] = $ tokens [$ i ]['content ' ].$ tokens [$ style ]['content ' ];
385
- $ tokens [$ style ]['column ' ] = $ tokens [$ i ]['column ' ];
386
-
387
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
388
- $ line = $ tokens [$ i ]['line ' ];
389
- echo "\t* T_LIST token $ i on line $ line merged into T_STYLE token $ style * " .PHP_EOL ;
390
- }
391
-
392
- // Now fix the brackets that surround this token as they will
393
- // be pointing too far ahead now that we have removed a token.
394
- for ($ t = $ i ; $ t >= 0 ; $ t --) {
395
- if (isset ($ tokens [$ t ]['bracket_closer ' ]) === true ) {
396
- $ old = $ tokens [$ t ]['bracket_closer ' ];
397
- $ tokens [$ t ]['bracket_closer ' ]--;
398
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
399
- $ new = $ tokens [$ t ]['bracket_closer ' ];
400
- $ type = $ tokens [$ t ]['type ' ];
401
- $ line = $ tokens [$ t ]['line ' ];
402
- echo "\t\t* $ type token $ t on line $ line closer changed from $ old to $ new * " .PHP_EOL ;
403
- }
404
-
405
- // Only need to fix one set of brackets.
406
- break ;
407
- }
408
- }
409
-
410
- // Now fix all future brackets as they are no longer pointing
411
- // to the correct tokens either.
412
- for ($ t = $ i ; $ t <= $ numTokens ; $ t ++) {
413
- if (isset ($ tokens [$ t ]) === false ) {
414
- break ;
415
- }
416
-
417
- if ($ tokens [$ t ]['code ' ] === T_OPEN_CURLY_BRACKET ) {
418
- $ old = $ tokens [$ t ]['bracket_closer ' ];
419
- $ tokens [$ t ]['bracket_closer ' ]--;
420
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
421
- $ new = $ tokens [$ t ]['bracket_closer ' ];
422
- $ type = $ tokens [$ t ]['type ' ];
423
- $ line = $ tokens [$ t ]['line ' ];
424
- echo "\t\t* $ type token $ t on line $ line closer changed from $ old to $ new * " .PHP_EOL ;
425
- }
426
-
427
- $ t = $ old ;
428
- }
429
- }
430
-
431
- unset($ tokens [$ i ]);
432
- $ changeMade = true ;
433
- $ i ++;
434
- } else if ($ tokens [$ i ]['code ' ] === T_BREAK ) {
435
- // Break is sometimes used in style definitions, like page-break-inside
436
- // so we need merge the elements around it into the next T_STYLE.
437
- $ newStyle = 'break ' .$ tokens [$ style ]['content ' ];
438
- for ($ x = ($ i - 1 ); $ x >= 0 ; $ x --) {
439
- if ($ tokens [$ x ]['code ' ] !== T_STRING && $ tokens [$ x ]['code ' ] !== T_MINUS ) {
440
- break ;
441
- }
442
-
443
- $ newStyle = $ tokens [$ x ]['content ' ].$ newStyle ;
444
- }
445
-
446
- $ x ++;
447
- $ tokens [$ style ]['content ' ] = $ newStyle ;
448
- $ tokens [$ style ]['column ' ] = $ tokens [$ x ]['column ' ];
449
-
450
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
451
- $ line = $ tokens [$ i ]['line ' ];
452
- echo "\t* tokens $ x - $ i on line $ line merged into T_STYLE token $ style due to T_BREAK at token $ i * " .PHP_EOL ;
453
- }
454
-
455
- // Now fix the brackets that surround this token as they will
456
- // be pointing too far ahead now that we have removed tokens.
457
- $ diff = ($ style - $ x );
458
- for ($ t = $ style ; $ t >= 0 ; $ t --) {
459
- if (isset ($ tokens [$ t ]['bracket_closer ' ]) === true ) {
460
- $ old = $ tokens [$ t ]['bracket_closer ' ];
461
- $ tokens [$ t ]['bracket_closer ' ] -= $ diff ;
462
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
463
- $ new = $ tokens [$ t ]['bracket_closer ' ];
464
- $ type = $ tokens [$ t ]['type ' ];
465
- $ line = $ tokens [$ t ]['line ' ];
466
- echo "\t\t* $ type token $ t on line $ line closer changed from $ old to $ new * " .PHP_EOL ;
467
- }
468
-
469
- // Only need to fix one set of brackets.
470
- break ;
471
- }
472
- }
473
-
474
- // Now fix all future brackets as they are no longer pointing
475
- // to the correct tokens either.
476
- for ($ t = $ style ; $ t <= $ numTokens ; $ t ++) {
477
- if (isset ($ tokens [$ t ]) === false ) {
478
- break ;
479
- }
480
-
481
- if ($ tokens [$ t ]['code ' ] === T_OPEN_CURLY_BRACKET ) {
482
- $ old = $ tokens [$ t ]['bracket_closer ' ];
483
- $ tokens [$ t ]['bracket_closer ' ] -= $ diff ;
484
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
485
- $ new = $ tokens [$ t ]['bracket_closer ' ];
486
- $ type = $ tokens [$ t ]['type ' ];
487
- $ line = $ tokens [$ t ]['line ' ];
488
- echo "\t\t* $ type token $ t on line $ line closer changed from $ old to $ new * " .PHP_EOL ;
489
- }
490
-
491
- $ t = $ old ;
492
- }
493
- }
494
-
495
- for ($ x ; $ x <= $ i ; $ x ++) {
496
- unset($ tokens [$ x ]);
497
- }
498
-
499
- $ changeMade = true ;
500
- $ i ++;
501
- }//end if
502
- }//end for
503
-
504
- if ($ changeMade === true ) {
505
- $ tokens = array_values ($ tokens );
506
- }
507
-
508
- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
509
- echo "\t*** END ADDITIONAL CSS PROCESSING *** " .PHP_EOL ;
510
- }
373
+ // We override this method because we don't want the PHP version to
374
+ // run during CSS processing because it is wasted processing time.
511
375
512
376
}//end processAdditional()
513
377
0 commit comments