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