annotate vendor/squizlabs/php_codesniffer/src/Tokenizers/CSS.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children 12f9dff5fda9
rev   line source
Chris@4 1 <?php
Chris@4 2 /**
Chris@4 3 * Tokenizes CSS code.
Chris@4 4 *
Chris@4 5 * @author Greg Sherwood <gsherwood@squiz.net>
Chris@4 6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Chris@4 7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
Chris@4 8 */
Chris@4 9
Chris@4 10 namespace PHP_CodeSniffer\Tokenizers;
Chris@4 11
Chris@4 12 use PHP_CodeSniffer\Util;
Chris@4 13 use PHP_CodeSniffer\Config;
Chris@4 14 use PHP_CodeSniffer\Exceptions\TokenizerException;
Chris@4 15
Chris@4 16 class CSS extends PHP
Chris@4 17 {
Chris@4 18
Chris@4 19
Chris@4 20 /**
Chris@4 21 * Initialise the tokenizer.
Chris@4 22 *
Chris@4 23 * Pre-checks the content to see if it looks minified.
Chris@4 24 *
Chris@4 25 * @param string $content The content to tokenize,
Chris@4 26 * @param \PHP_CodeSniffer\Config $config The config data for the run.
Chris@4 27 * @param string $eolChar The EOL char used in the content.
Chris@4 28 *
Chris@4 29 * @return void
Chris@4 30 * @throws TokenizerException If the file appears to be minified.
Chris@4 31 */
Chris@4 32 public function __construct($content, Config $config, $eolChar='\n')
Chris@4 33 {
Chris@4 34 if ($this->isMinifiedContent($content, $eolChar) === true) {
Chris@4 35 throw new TokenizerException('File appears to be minified and cannot be processed');
Chris@4 36 }
Chris@4 37
Chris@4 38 return parent::__construct($content, $config, $eolChar);
Chris@4 39
Chris@4 40 }//end __construct()
Chris@4 41
Chris@4 42
Chris@4 43 /**
Chris@4 44 * Creates an array of tokens when given some CSS code.
Chris@4 45 *
Chris@4 46 * Uses the PHP tokenizer to do all the tricky work
Chris@4 47 *
Chris@4 48 * @param string $string The string to tokenize.
Chris@4 49 *
Chris@4 50 * @return array
Chris@4 51 */
Chris@4 52 public function tokenize($string)
Chris@4 53 {
Chris@4 54 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 55 echo "\t*** START CSS TOKENIZING 1ST PASS ***".PHP_EOL;
Chris@4 56 }
Chris@4 57
Chris@4 58 // If the content doesn't have an EOL char on the end, add one so
Chris@4 59 // the open and close tags we add are parsed correctly.
Chris@4 60 $eolAdded = false;
Chris@4 61 if (substr($string, (strlen($this->eolChar) * -1)) !== $this->eolChar) {
Chris@4 62 $string .= $this->eolChar;
Chris@4 63 $eolAdded = true;
Chris@4 64 }
Chris@4 65
Chris@4 66 $string = str_replace('<?php', '^PHPCS_CSS_T_OPEN_TAG^', $string);
Chris@4 67 $string = str_replace('?>', '^PHPCS_CSS_T_CLOSE_TAG^', $string);
Chris@4 68 $tokens = parent::tokenize('<?php '.$string.'?>');
Chris@4 69
Chris@4 70 $finalTokens = [];
Chris@4 71 $finalTokens[0] = [
Chris@4 72 'code' => T_OPEN_TAG,
Chris@4 73 'type' => 'T_OPEN_TAG',
Chris@4 74 'content' => '',
Chris@4 75 ];
Chris@4 76
Chris@4 77 $newStackPtr = 1;
Chris@4 78 $numTokens = count($tokens);
Chris@4 79 $multiLineComment = false;
Chris@4 80 for ($stackPtr = 1; $stackPtr < $numTokens; $stackPtr++) {
Chris@4 81 $token = $tokens[$stackPtr];
Chris@4 82
Chris@4 83 // CSS files don't have lists, breaks etc, so convert these to
Chris@4 84 // standard strings early so they can be converted into T_STYLE
Chris@4 85 // tokens and joined with other strings if needed.
Chris@4 86 if ($token['code'] === T_BREAK
Chris@4 87 || $token['code'] === T_LIST
Chris@4 88 || $token['code'] === T_DEFAULT
Chris@4 89 || $token['code'] === T_SWITCH
Chris@4 90 || $token['code'] === T_FOR
Chris@4 91 || $token['code'] === T_FOREACH
Chris@4 92 || $token['code'] === T_WHILE
Chris@4 93 || $token['code'] === T_DEC
Chris@4 94 || $token['code'] === T_NEW
Chris@4 95 ) {
Chris@4 96 $token['type'] = 'T_STRING';
Chris@4 97 $token['code'] = T_STRING;
Chris@4 98 }
Chris@4 99
Chris@4 100 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 101 $type = $token['type'];
Chris@4 102 $content = Util\Common::prepareForOutput($token['content']);
Chris@4 103 echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
Chris@4 104 }
Chris@4 105
Chris@4 106 if ($token['code'] === T_BITWISE_XOR
Chris@4 107 && $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_OPEN_TAG'
Chris@4 108 ) {
Chris@4 109 $content = '<?php';
Chris@4 110 for ($stackPtr += 3; $stackPtr < $numTokens; $stackPtr++) {
Chris@4 111 if ($tokens[$stackPtr]['code'] === T_BITWISE_XOR
Chris@4 112 && $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_CLOSE_TAG'
Chris@4 113 ) {
Chris@4 114 // Add the end tag and ignore the * we put at the end.
Chris@4 115 $content .= '?>';
Chris@4 116 $stackPtr += 2;
Chris@4 117 break;
Chris@4 118 } else {
Chris@4 119 $content .= $tokens[$stackPtr]['content'];
Chris@4 120 }
Chris@4 121 }
Chris@4 122
Chris@4 123 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 124 echo "\t\t=> Found embedded PHP code: ";
Chris@4 125 $cleanContent = Util\Common::prepareForOutput($content);
Chris@4 126 echo $cleanContent.PHP_EOL;
Chris@4 127 }
Chris@4 128
Chris@4 129 $finalTokens[$newStackPtr] = [
Chris@4 130 'type' => 'T_EMBEDDED_PHP',
Chris@4 131 'code' => T_EMBEDDED_PHP,
Chris@4 132 'content' => $content,
Chris@4 133 ];
Chris@4 134
Chris@4 135 $newStackPtr++;
Chris@4 136 continue;
Chris@4 137 }//end if
Chris@4 138
Chris@4 139 if ($token['code'] === T_GOTO_LABEL) {
Chris@4 140 // Convert these back to T_STRING followed by T_COLON so we can
Chris@4 141 // more easily process style definitions.
Chris@4 142 $finalTokens[$newStackPtr] = [
Chris@4 143 'type' => 'T_STRING',
Chris@4 144 'code' => T_STRING,
Chris@4 145 'content' => substr($token['content'], 0, -1),
Chris@4 146 ];
Chris@4 147 $newStackPtr++;
Chris@4 148 $finalTokens[$newStackPtr] = [
Chris@4 149 'type' => 'T_COLON',
Chris@4 150 'code' => T_COLON,
Chris@4 151 'content' => ':',
Chris@4 152 ];
Chris@4 153 $newStackPtr++;
Chris@4 154 continue;
Chris@4 155 }
Chris@4 156
Chris@4 157 if ($token['code'] === T_FUNCTION) {
Chris@4 158 // There are no functions in CSS, so convert this to a string.
Chris@4 159 $finalTokens[$newStackPtr] = [
Chris@4 160 'type' => 'T_STRING',
Chris@4 161 'code' => T_STRING,
Chris@4 162 'content' => $token['content'],
Chris@4 163 ];
Chris@4 164
Chris@4 165 $newStackPtr++;
Chris@4 166 continue;
Chris@4 167 }
Chris@4 168
Chris@4 169 if ($token['code'] === T_COMMENT
Chris@4 170 && substr($token['content'], 0, 2) === '/*'
Chris@4 171 ) {
Chris@4 172 // Multi-line comment. Record it so we can ignore other
Chris@4 173 // comment tags until we get out of this one.
Chris@4 174 $multiLineComment = true;
Chris@4 175 }
Chris@4 176
Chris@4 177 if ($token['code'] === T_COMMENT
Chris@4 178 && $multiLineComment === false
Chris@4 179 && (substr($token['content'], 0, 2) === '//'
Chris@4 180 || $token['content']{0} === '#')
Chris@4 181 ) {
Chris@4 182 $content = ltrim($token['content'], '#/');
Chris@4 183
Chris@4 184 // Guard against PHP7+ syntax errors by stripping
Chris@4 185 // leading zeros so the content doesn't look like an invalid int.
Chris@4 186 $leadingZero = false;
Chris@4 187 if ($content{0} === '0') {
Chris@4 188 $content = '1'.$content;
Chris@4 189 $leadingZero = true;
Chris@4 190 }
Chris@4 191
Chris@4 192 $commentTokens = parent::tokenize('<?php '.$content.'?>');
Chris@4 193
Chris@4 194 // The first and last tokens are the open/close tags.
Chris@4 195 array_shift($commentTokens);
Chris@4 196 array_pop($commentTokens);
Chris@4 197
Chris@4 198 if ($leadingZero === true) {
Chris@4 199 $commentTokens[0]['content'] = substr($commentTokens[0]['content'], 1);
Chris@4 200 $content = substr($content, 1);
Chris@4 201 }
Chris@4 202
Chris@4 203 if ($token['content']{0} === '#') {
Chris@4 204 // The # character is not a comment in CSS files, so
Chris@4 205 // determine what it means in this context.
Chris@4 206 $firstContent = $commentTokens[0]['content'];
Chris@4 207
Chris@4 208 // If the first content is just a number, it is probably a
Chris@4 209 // colour like 8FB7DB, which PHP splits into 8 and FB7DB.
Chris@4 210 if (($commentTokens[0]['code'] === T_LNUMBER
Chris@4 211 || $commentTokens[0]['code'] === T_DNUMBER)
Chris@4 212 && $commentTokens[1]['code'] === T_STRING
Chris@4 213 ) {
Chris@4 214 $firstContent .= $commentTokens[1]['content'];
Chris@4 215 array_shift($commentTokens);
Chris@4 216 }
Chris@4 217
Chris@4 218 // If the first content looks like a colour and not a class
Chris@4 219 // definition, join the tokens together.
Chris@4 220 if (preg_match('/^[ABCDEF0-9]+$/i', $firstContent) === 1
Chris@4 221 && $commentTokens[1]['content'] !== '-'
Chris@4 222 ) {
Chris@4 223 array_shift($commentTokens);
Chris@4 224 // Work out what we trimmed off above and remember to re-add it.
Chris@4 225 $trimmed = substr($token['content'], 0, (strlen($token['content']) - strlen($content)));
Chris@4 226 $finalTokens[$newStackPtr] = [
Chris@4 227 'type' => 'T_COLOUR',
Chris@4 228 'code' => T_COLOUR,
Chris@4 229 'content' => $trimmed.$firstContent,
Chris@4 230 ];
Chris@4 231 } else {
Chris@4 232 $finalTokens[$newStackPtr] = [
Chris@4 233 'type' => 'T_HASH',
Chris@4 234 'code' => T_HASH,
Chris@4 235 'content' => '#',
Chris@4 236 ];
Chris@4 237 }
Chris@4 238 } else {
Chris@4 239 $finalTokens[$newStackPtr] = [
Chris@4 240 'type' => 'T_STRING',
Chris@4 241 'code' => T_STRING,
Chris@4 242 'content' => '//',
Chris@4 243 ];
Chris@4 244 }//end if
Chris@4 245
Chris@4 246 $newStackPtr++;
Chris@4 247
Chris@4 248 array_splice($tokens, $stackPtr, 1, $commentTokens);
Chris@4 249 $numTokens = count($tokens);
Chris@4 250 $stackPtr--;
Chris@4 251 continue;
Chris@4 252 }//end if
Chris@4 253
Chris@4 254 if ($token['code'] === T_COMMENT
Chris@4 255 && substr($token['content'], -2) === '*/'
Chris@4 256 ) {
Chris@4 257 // Multi-line comment is done.
Chris@4 258 $multiLineComment = false;
Chris@4 259 }
Chris@4 260
Chris@4 261 $finalTokens[$newStackPtr] = $token;
Chris@4 262 $newStackPtr++;
Chris@4 263 }//end for
Chris@4 264
Chris@4 265 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 266 echo "\t*** END CSS TOKENIZING 1ST PASS ***".PHP_EOL;
Chris@4 267 echo "\t*** START CSS TOKENIZING 2ND PASS ***".PHP_EOL;
Chris@4 268 }
Chris@4 269
Chris@4 270 // A flag to indicate if we are inside a style definition,
Chris@4 271 // which is defined using curly braces.
Chris@4 272 $inStyleDef = false;
Chris@4 273
Chris@4 274 // A flag to indicate if an At-rule like "@media" is used, which will result
Chris@4 275 // in nested curly brackets.
Chris@4 276 $asperandStart = false;
Chris@4 277
Chris@4 278 $numTokens = count($finalTokens);
Chris@4 279 for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
Chris@4 280 $token = $finalTokens[$stackPtr];
Chris@4 281
Chris@4 282 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 283 $type = $token['type'];
Chris@4 284 $content = Util\Common::prepareForOutput($token['content']);
Chris@4 285 echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
Chris@4 286 }
Chris@4 287
Chris@4 288 switch ($token['code']) {
Chris@4 289 case T_OPEN_CURLY_BRACKET:
Chris@4 290 // Opening curly brackets for an At-rule do not start a style
Chris@4 291 // definition. We also reset the asperand flag here because the next
Chris@4 292 // opening curly bracket could be indeed the start of a style
Chris@4 293 // definition.
Chris@4 294 if ($asperandStart === true) {
Chris@4 295 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 296 if ($inStyleDef === true) {
Chris@4 297 echo "\t\t* style definition closed *".PHP_EOL;
Chris@4 298 }
Chris@4 299
Chris@4 300 if ($asperandStart === true) {
Chris@4 301 echo "\t\t* at-rule definition closed *".PHP_EOL;
Chris@4 302 }
Chris@4 303 }
Chris@4 304
Chris@4 305 $inStyleDef = false;
Chris@4 306 $asperandStart = false;
Chris@4 307 } else {
Chris@4 308 $inStyleDef = true;
Chris@4 309 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 310 echo "\t\t* style definition opened *".PHP_EOL;
Chris@4 311 }
Chris@4 312 }
Chris@4 313 break;
Chris@4 314 case T_CLOSE_CURLY_BRACKET:
Chris@4 315 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 316 if ($inStyleDef === true) {
Chris@4 317 echo "\t\t* style definition closed *".PHP_EOL;
Chris@4 318 }
Chris@4 319
Chris@4 320 if ($asperandStart === true) {
Chris@4 321 echo "\t\t* at-rule definition closed *".PHP_EOL;
Chris@4 322 }
Chris@4 323 }
Chris@4 324
Chris@4 325 $inStyleDef = false;
Chris@4 326 $asperandStart = false;
Chris@4 327 break;
Chris@4 328 case T_MINUS:
Chris@4 329 // Minus signs are often used instead of spaces inside
Chris@4 330 // class names, IDs and styles.
Chris@4 331 if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) {
Chris@4 332 if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) {
Chris@4 333 $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content'];
Chris@4 334
Chris@4 335 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 336 echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL;
Chris@4 337 $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']);
Chris@4 338 $new = Util\Common::prepareForOutput($newContent);
Chris@4 339 echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL;
Chris@4 340 }
Chris@4 341
Chris@4 342 $finalTokens[($stackPtr + 1)]['content'] = $newContent;
Chris@4 343 unset($finalTokens[$stackPtr]);
Chris@4 344 unset($finalTokens[($stackPtr - 1)]);
Chris@4 345 } else {
Chris@4 346 $newContent = '-'.$finalTokens[($stackPtr + 1)]['content'];
Chris@4 347
Chris@4 348 $finalTokens[($stackPtr + 1)]['content'] = $newContent;
Chris@4 349 unset($finalTokens[$stackPtr]);
Chris@4 350 }
Chris@4 351 } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) {
Chris@4 352 // They can also be used to provide negative numbers.
Chris@4 353 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 354 echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL;
Chris@4 355 $content = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']);
Chris@4 356 echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL;
Chris@4 357 }
Chris@4 358
Chris@4 359 $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content'];
Chris@4 360 unset($finalTokens[$stackPtr]);
Chris@4 361 }//end if
Chris@4 362 break;
Chris@4 363 case T_COLON:
Chris@4 364 // Only interested in colons that are defining styles.
Chris@4 365 if ($inStyleDef === false) {
Chris@4 366 break;
Chris@4 367 }
Chris@4 368
Chris@4 369 for ($x = ($stackPtr - 1); $x >= 0; $x--) {
Chris@4 370 if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) {
Chris@4 371 break;
Chris@4 372 }
Chris@4 373 }
Chris@4 374
Chris@4 375 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 376 $type = $finalTokens[$x]['type'];
Chris@4 377 echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL;
Chris@4 378 }
Chris@4 379
Chris@4 380 $finalTokens[$x]['type'] = 'T_STYLE';
Chris@4 381 $finalTokens[$x]['code'] = T_STYLE;
Chris@4 382 break;
Chris@4 383 case T_STRING:
Chris@4 384 if (strtolower($token['content']) === 'url') {
Chris@4 385 // Find the next content.
Chris@4 386 for ($x = ($stackPtr + 1); $x < $numTokens; $x++) {
Chris@4 387 if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) {
Chris@4 388 break;
Chris@4 389 }
Chris@4 390 }
Chris@4 391
Chris@4 392 // Needs to be in the format "url(" for it to be a URL.
Chris@4 393 if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) {
Chris@4 394 continue 2;
Chris@4 395 }
Chris@4 396
Chris@4 397 // Make sure the content isn't empty.
Chris@4 398 for ($y = ($x + 1); $y < $numTokens; $y++) {
Chris@4 399 if (isset(Util\Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) {
Chris@4 400 break;
Chris@4 401 }
Chris@4 402 }
Chris@4 403
Chris@4 404 if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) {
Chris@4 405 continue 2;
Chris@4 406 }
Chris@4 407
Chris@4 408 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 409 for ($i = ($stackPtr + 1); $i <= $y; $i++) {
Chris@4 410 $type = $finalTokens[$i]['type'];
Chris@4 411 $content = Util\Common::prepareForOutput($finalTokens[$i]['content']);
Chris@4 412 echo "\tProcess token $i: $type => $content".PHP_EOL;
Chris@4 413 }
Chris@4 414
Chris@4 415 echo "\t\t* token starts a URL *".PHP_EOL;
Chris@4 416 }
Chris@4 417
Chris@4 418 // Join all the content together inside the url() statement.
Chris@4 419 $newContent = '';
Chris@4 420 for ($i = ($x + 2); $i < $numTokens; $i++) {
Chris@4 421 if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
Chris@4 422 break;
Chris@4 423 }
Chris@4 424
Chris@4 425 $newContent .= $finalTokens[$i]['content'];
Chris@4 426 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 427 $content = Util\Common::prepareForOutput($finalTokens[$i]['content']);
Chris@4 428 echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL;
Chris@4 429 }
Chris@4 430
Chris@4 431 unset($finalTokens[$i]);
Chris@4 432 }
Chris@4 433
Chris@4 434 $stackPtr = $i;
Chris@4 435
Chris@4 436 // If the content inside the "url()" is in double quotes
Chris@4 437 // there will only be one token and so we don't have to do
Chris@4 438 // anything except change its type. If it is not empty,
Chris@4 439 // we need to do some token merging.
Chris@4 440 $finalTokens[($x + 1)]['type'] = 'T_URL';
Chris@4 441 $finalTokens[($x + 1)]['code'] = T_URL;
Chris@4 442
Chris@4 443 if ($newContent !== '') {
Chris@4 444 $finalTokens[($x + 1)]['content'] .= $newContent;
Chris@4 445 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 446 $content = Util\Common::prepareForOutput($finalTokens[($x + 1)]['content']);
Chris@4 447 echo "\t\t=> token content changed to: $content".PHP_EOL;
Chris@4 448 }
Chris@4 449 }
Chris@4 450 } else if ($finalTokens[$stackPtr]['content'][0] === '-'
Chris@4 451 && $finalTokens[($stackPtr + 1)]['code'] === T_STRING
Chris@4 452 ) {
Chris@4 453 if (isset($finalTokens[($stackPtr - 1)]) === true
Chris@4 454 && $finalTokens[($stackPtr - 1)]['code'] === T_STRING
Chris@4 455 ) {
Chris@4 456 $newContent = $finalTokens[($stackPtr - 1)]['content'].$finalTokens[$stackPtr]['content'].$finalTokens[($stackPtr + 1)]['content'];
Chris@4 457
Chris@4 458 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 459 echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL;
Chris@4 460 $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']);
Chris@4 461 $new = Util\Common::prepareForOutput($newContent);
Chris@4 462 echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL;
Chris@4 463 }
Chris@4 464
Chris@4 465 $finalTokens[($stackPtr + 1)]['content'] = $newContent;
Chris@4 466 unset($finalTokens[$stackPtr]);
Chris@4 467 unset($finalTokens[($stackPtr - 1)]);
Chris@4 468 } else {
Chris@4 469 $newContent = $finalTokens[$stackPtr]['content'].$finalTokens[($stackPtr + 1)]['content'];
Chris@4 470
Chris@4 471 $finalTokens[($stackPtr + 1)]['content'] = $newContent;
Chris@4 472 unset($finalTokens[$stackPtr]);
Chris@4 473 }
Chris@4 474 }//end if
Chris@4 475 break;
Chris@4 476 case T_ASPERAND:
Chris@4 477 $asperandStart = true;
Chris@4 478 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 479 echo "\t\t* at-rule definition opened *".PHP_EOL;
Chris@4 480 }
Chris@4 481 break;
Chris@4 482 default:
Chris@4 483 // Nothing special to be done with this token.
Chris@4 484 break;
Chris@4 485 }//end switch
Chris@4 486 }//end for
Chris@4 487
Chris@4 488 // Reset the array keys to avoid gaps.
Chris@4 489 $finalTokens = array_values($finalTokens);
Chris@4 490 $numTokens = count($finalTokens);
Chris@4 491
Chris@4 492 // Blank out the content of the end tag.
Chris@4 493 $finalTokens[($numTokens - 1)]['content'] = '';
Chris@4 494
Chris@4 495 if ($eolAdded === true) {
Chris@4 496 // Strip off the extra EOL char we added for tokenizing.
Chris@4 497 $finalTokens[($numTokens - 2)]['content'] = substr(
Chris@4 498 $finalTokens[($numTokens - 2)]['content'],
Chris@4 499 0,
Chris@4 500 (strlen($this->eolChar) * -1)
Chris@4 501 );
Chris@4 502
Chris@4 503 if ($finalTokens[($numTokens - 2)]['content'] === '') {
Chris@4 504 unset($finalTokens[($numTokens - 2)]);
Chris@4 505 $finalTokens = array_values($finalTokens);
Chris@4 506 $numTokens = count($finalTokens);
Chris@4 507 }
Chris@4 508 }
Chris@4 509
Chris@4 510 if (PHP_CODESNIFFER_VERBOSITY > 1) {
Chris@4 511 echo "\t*** END CSS TOKENIZING 2ND PASS ***".PHP_EOL;
Chris@4 512 }
Chris@4 513
Chris@4 514 return $finalTokens;
Chris@4 515
Chris@4 516 }//end tokenize()
Chris@4 517
Chris@4 518
Chris@4 519 /**
Chris@4 520 * Performs additional processing after main tokenizing.
Chris@4 521 *
Chris@4 522 * @return void
Chris@4 523 */
Chris@4 524 public function processAdditional()
Chris@4 525 {
Chris@4 526 /*
Chris@4 527 We override this method because we don't want the PHP version to
Chris@4 528 run during CSS processing because it is wasted processing time.
Chris@4 529 */
Chris@4 530
Chris@4 531 }//end processAdditional()
Chris@4 532
Chris@4 533
Chris@4 534 }//end class