GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 699b70...879176 )
by Chris
13:23
created

PHP_CodeSniffer_Tokenizers_CSS   F

Complexity

Total Complexity 81

Size/Duplication

Total Lines 483
Duplicated Lines 13.87 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 67
loc 483
rs 1.5789
c 0
b 0
f 0
wmc 81
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
F tokenizeString() 67 441 80
A processAdditional() 0 8 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like PHP_CodeSniffer_Tokenizers_CSS often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PHP_CodeSniffer_Tokenizers_CSS, and based on these observations, apply Extract Interface, too.

1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Tokenizes CSS code.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <[email protected]>
10
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12
 * @link      http://pear.php.net/package/PHP_CodeSniffer
13
 */
14
15
if (class_exists('PHP_CodeSniffer_Tokenizers_PHP', true) === false) {
16
    throw new Exception('Class PHP_CodeSniffer_Tokenizers_PHP not found');
17
}
18
19
/**
20
 * Tokenizes CSS code.
21
 *
22
 * @category  PHP
23
 * @package   PHP_CodeSniffer
24
 * @author    Greg Sherwood <[email protected]>
25
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
26
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
27
 * @version   Release: @package_version@
28
 * @link      http://pear.php.net/package/PHP_CodeSniffer
29
 */
30
class PHP_CodeSniffer_Tokenizers_CSS extends PHP_CodeSniffer_Tokenizers_PHP
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
31
{
32
33
    /**
34
     * If TRUE, files that appear to be minified will not be processed.
35
     *
36
     * @var boolean
37
     */
38
    public $skipMinified = true;
39
40
41
    /**
42
     * Creates an array of tokens when given some CSS code.
43
     *
44
     * Uses the PHP tokenizer to do all the tricky work
45
     *
46
     * @param string $string  The string to tokenize.
47
     * @param string $eolChar The EOL character to use for splitting strings.
48
     *
49
     * @return array
50
     */
51
    public function tokenizeString($string, $eolChar='\n')
52
    {
53
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
54
            echo "\t*** START CSS TOKENIZING 1ST PASS ***".PHP_EOL;
55
        }
56
57
        // If the content doesn't have an EOL char on the end, add one so
58
        // the open and close tags we add are parsed correctly.
59
        $eolAdded = false;
60
        if (substr($string, (strlen($eolChar) * -1)) !== $eolChar) {
61
            $string  .= $eolChar;
62
            $eolAdded = true;
63
        }
64
65
        $string = str_replace('<?php', '^PHPCS_CSS_T_OPEN_TAG^', $string);
66
        $string = str_replace('?>', '^PHPCS_CSS_T_CLOSE_TAG^', $string);
67
        $tokens = parent::tokenizeString('<?php '.$string.'?>', $eolChar);
68
69
        $finalTokens    = array();
70
        $finalTokens[0] = array(
71
                           'code'    => T_OPEN_TAG,
72
                           'type'    => 'T_OPEN_TAG',
73
                           'content' => '',
74
                          );
75
76
        $newStackPtr      = 1;
77
        $numTokens        = count($tokens);
78
        $multiLineComment = false;
79
        for ($stackPtr = 1; $stackPtr < $numTokens; $stackPtr++) {
0 ignored issues
show
Comprehensibility Bug introduced by
Loop incrementor ($stackPtr) jumbling with inner loop
Loading history...
80
            $token = $tokens[$stackPtr];
81
82
            // CSS files don't have lists, breaks etc, so convert these to
83
            // standard strings early so they can be converted into T_STYLE
84
            // tokens and joined with other strings if needed.
85
            if ($token['code'] === T_BREAK
86
                || $token['code'] === T_LIST
87
                || $token['code'] === T_DEFAULT
88
                || $token['code'] === T_SWITCH
89
                || $token['code'] === T_FOR
90
                || $token['code'] === T_FOREACH
91
                || $token['code'] === T_WHILE
92
            ) {
93
                $token['type'] = 'T_STRING';
94
                $token['code'] = T_STRING;
95
            }
96
97
            if (PHP_CODESNIFFER_VERBOSITY > 1) {
98
                $type    = $token['type'];
99
                $content = PHP_CodeSniffer::prepareForOutput($token['content']);
100
                echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
101
            }
102
103
            if ($token['code'] === T_BITWISE_XOR
104
                && $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_OPEN_TAG'
105
            ) {
106
                $content = '<?php';
107
                for ($stackPtr = ($stackPtr + 3); $stackPtr < $numTokens; $stackPtr++) {
108
                    if ($tokens[$stackPtr]['code'] === T_BITWISE_XOR
109
                        && $tokens[($stackPtr + 1)]['content'] === 'PHPCS_CSS_T_CLOSE_TAG'
110
                    ) {
111
                        // Add the end tag and ignore the * we put at the end.
112
                        $content  .= '?>';
113
                        $stackPtr += 2;
114
                        break;
115
                    } else {
116
                        $content .= $tokens[$stackPtr]['content'];
117
                    }
118
                }
119
120
                if (PHP_CODESNIFFER_VERBOSITY > 1) {
121
                    echo "\t\t=> Found embedded PHP code: ";
122
                    $cleanContent = PHP_CodeSniffer::prepareForOutput($content);
123
                    echo $cleanContent.PHP_EOL;
124
                }
125
126
                $finalTokens[$newStackPtr] = array(
127
                                              'type'    => 'T_EMBEDDED_PHP',
128
                                              'code'    => T_EMBEDDED_PHP,
129
                                              'content' => $content,
130
                                             );
131
132
                $newStackPtr++;
133
                continue;
134
            }//end if
135
136
            if ($token['code'] === T_GOTO_LABEL) {
137
                // Convert these back to T_STRING followed by T_COLON so we can
138
                // more easily process style definitions.
139
                $finalTokens[$newStackPtr] = array(
140
                                              'type'    => 'T_STRING',
141
                                              'code'    => T_STRING,
142
                                              'content' => substr($token['content'], 0, -1),
143
                                             );
144
                $newStackPtr++;
145
                $finalTokens[$newStackPtr] = array(
146
                                              'type'    => 'T_COLON',
147
                                              'code'    => T_COLON,
148
                                              'content' => ':',
149
                                             );
150
                $newStackPtr++;
151
                continue;
152
            }
153
154 View Code Duplication
            if ($token['code'] === T_FUNCTION) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
                // There are no functions in CSS, so convert this to a string.
156
                $finalTokens[$newStackPtr] = array(
157
                                              'type'    => 'T_STRING',
158
                                              'code'    => T_STRING,
159
                                              'content' => $token['content'],
160
                                             );
161
162
                $newStackPtr++;
163
                continue;
164
            }
165
166 View Code Duplication
            if ($token['code'] === T_COMMENT
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
                && substr($token['content'], 0, 2) === '/*'
168
            ) {
169
                // Multi-line comment. Record it so we can ignore other
170
                // comment tags until we get out of this one.
171
                $multiLineComment = true;
172
            }
173
174
            if ($token['code'] === T_COMMENT
175
                && $multiLineComment === false
176
                && (substr($token['content'], 0, 2) === '//'
177
                || $token['content']{0} === '#')
178
            ) {
179
                $content = ltrim($token['content'], '#/');
180
181
                // Guard against PHP7+ syntax errors by stripping
182
                // leading zeros so the content doesn't look like an invalid int.
183
                $leadingZero = false;
184
                if ($content{0} === '0') {
185
                    $content     = '1'.$content;
186
                    $leadingZero = true;
187
                }
188
189
                $commentTokens = parent::tokenizeString('<?php '.$content.'?>', $eolChar);
190
191
                // The first and last tokens are the open/close tags.
192
                array_shift($commentTokens);
193
                array_pop($commentTokens);
194
195
                if ($leadingZero === true) {
196
                    $commentTokens[0]['content'] = substr($commentTokens[0]['content'], 1);
197
                    $content = substr($content, 1);
198
                }
199
200
                if ($token['content']{0} === '#') {
201
                    // The # character is not a comment in CSS files, so
202
                    // determine what it means in this context.
203
                    $firstContent = $commentTokens[0]['content'];
204
205
                    // If the first content is just a number, it is probably a
206
                    // colour like 8FB7DB, which PHP splits into 8 and FB7DB.
207
                    if (($commentTokens[0]['code'] === T_LNUMBER
208
                        || $commentTokens[0]['code'] === T_DNUMBER)
209
                        && $commentTokens[1]['code'] === T_STRING
210
                    ) {
211
                        $firstContent .= $commentTokens[1]['content'];
212
                        array_shift($commentTokens);
213
                    }
214
215
                    // If the first content looks like a colour and not a class
216
                    // definition, join the tokens together.
217
                    if (preg_match('/^[ABCDEF0-9]+$/i', $firstContent) === 1
218
                        && $commentTokens[1]['content'] !== '-'
219
                    ) {
220
                        array_shift($commentTokens);
221
                        // Work out what we trimmed off above and remember to re-add it.
222
                        $trimmed = substr($token['content'], 0, (strlen($token['content']) - strlen($content)));
223
                        $finalTokens[$newStackPtr] = array(
224
                                                      'type'    => 'T_COLOUR',
225
                                                      'code'    => T_COLOUR,
226
                                                      'content' => $trimmed.$firstContent,
227
                                                     );
228
                    } else {
229
                        $finalTokens[$newStackPtr] = array(
230
                                                      'type'    => 'T_HASH',
231
                                                      'code'    => T_HASH,
232
                                                      'content' => '#',
233
                                                     );
234
                    }
235
                } else {
236
                    $finalTokens[$newStackPtr] = array(
237
                                                  'type'    => 'T_STRING',
238
                                                  'code'    => T_STRING,
239
                                                  'content' => '//',
240
                                                 );
241
                }//end if
242
243
                $newStackPtr++;
244
245
                array_splice($tokens, $stackPtr, 1, $commentTokens);
246
                $numTokens = count($tokens);
247
                $stackPtr--;
248
                continue;
249
            }//end if
250
251 View Code Duplication
            if ($token['code'] === T_COMMENT
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
                && substr($token['content'], -2) === '*/'
253
            ) {
254
                // Multi-line comment is done.
255
                $multiLineComment = false;
256
            }
257
258
            $finalTokens[$newStackPtr] = $token;
259
            $newStackPtr++;
260
        }//end for
261
262
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
263
            echo "\t*** END CSS TOKENIZING 1ST PASS ***".PHP_EOL;
264
            echo "\t*** START CSS TOKENIZING 2ND PASS ***".PHP_EOL;
265
        }
266
267
        // A flag to indicate if we are inside a style definition,
268
        // which is defined using curly braces.
269
        $inStyleDef = false;
270
271
        // A flag to indicate if an At-rule like "@media" is used, which will result
272
        // in nested curly brackets.
273
        $asperandStart = false;
274
275
        $numTokens = count($finalTokens);
276
        for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
277
            $token = $finalTokens[$stackPtr];
278
279
            if (PHP_CODESNIFFER_VERBOSITY > 1) {
280
                $type    = $token['type'];
281
                $content = PHP_CodeSniffer::prepareForOutput($token['content']);
282
                echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
283
            }
284
285
            switch ($token['code']) {
286
            case T_OPEN_CURLY_BRACKET:
287
                // Opening curly brackets for an At-rule do not start a style
288
                // definition. We also reset the asperand flag here because the next
289
                // opening curly bracket could be indeed the start of a style
290
                // definition.
291
                if ($asperandStart === true) {
292 View Code Duplication
                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
293
                        if ($inStyleDef === true) {
294
                            echo "\t\t* style definition closed *".PHP_EOL;
295
                        }
296
297
                        if ($asperandStart === true) {
298
                            echo "\t\t* at-rule definition closed *".PHP_EOL;
299
                        }
300
                    }
301
302
                    $inStyleDef    = false;
303
                    $asperandStart = false;
304
                } else {
305
                    $inStyleDef = true;
306
                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
307
                        echo "\t\t* style definition opened *".PHP_EOL;
308
                    }
309
                }
310
                break;
311
            case T_CLOSE_CURLY_BRACKET:
312 View Code Duplication
                if (PHP_CODESNIFFER_VERBOSITY > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
313
                    if ($inStyleDef === true) {
314
                        echo "\t\t* style definition closed *".PHP_EOL;
315
                    }
316
317
                    if ($asperandStart === true) {
318
                        echo "\t\t* at-rule definition closed *".PHP_EOL;
319
                    }
320
                }
321
322
                $inStyleDef    = false;
323
                $asperandStart = false;
324
                break;
325
            case T_MINUS:
326
                // Minus signs are often used instead of spaces inside
327
                // class names, IDs and styles.
328
                if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) {
329
                    if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) {
330
                        $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content'];
331
332 View Code Duplication
                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
333
                            echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL;
334
                            $old = PHP_CodeSniffer::prepareForOutput($finalTokens[($stackPtr + 1)]['content']);
335
                            $new = PHP_CodeSniffer::prepareForOutput($newContent);
336
                            echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL;
337
                        }
338
339
                        $finalTokens[($stackPtr + 1)]['content'] = $newContent;
340
                        unset($finalTokens[$stackPtr]);
341
                        unset($finalTokens[($stackPtr - 1)]);
342
                    } else {
343
                        $newContent = '-'.$finalTokens[($stackPtr + 1)]['content'];
344
345
                        $finalTokens[($stackPtr + 1)]['content'] = $newContent;
346
                        unset($finalTokens[$stackPtr]);
347
                    }
348
                } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) {
349
                    // They can also be used to provide negative numbers.
350 View Code Duplication
                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
351
                        echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL;
352
                        $content = PHP_CodeSniffer::prepareForOutput($finalTokens[($stackPtr + 1)]['content']);
353
                        echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL;
354
                    }
355
356
                    $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content'];
357
                    unset($finalTokens[$stackPtr]);
358
                }//end if
359
360
                break;
361
            case T_COLON:
362
                // Only interested in colons that are defining styles.
363
                if ($inStyleDef === false) {
364
                    break;
365
                }
366
367
                for ($x = ($stackPtr - 1); $x >= 0; $x--) {
368
                    if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) {
369
                        break;
370
                    }
371
                }
372
373
                if (PHP_CODESNIFFER_VERBOSITY > 1) {
374
                    $type = $finalTokens[$x]['type'];
375
                    echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL;
376
                }
377
378
                $finalTokens[$x]['type'] = 'T_STYLE';
379
                $finalTokens[$x]['code'] = T_STYLE;
380
                break;
381
            case T_STRING:
382
                if (strtolower($token['content']) === 'url') {
383
                    // Find the next content.
384 View Code Duplication
                    for ($x = ($stackPtr + 1); $x < $numTokens; $x++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
385
                        if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) {
386
                            break;
387
                        }
388
                    }
389
390
                    // Needs to be in the format "url(" for it to be a URL.
391
                    if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) {
392
                        continue;
393
                    }
394
395
                    // Make sure the content isn't empty.
396 View Code Duplication
                    for ($y = ($x + 1); $y < $numTokens; $y++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
                        if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) {
398
                            break;
399
                        }
400
                    }
401
402
                    if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) {
403
                        continue;
404
                    }
405
406
                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
407
                        for ($i = ($stackPtr + 1); $i <= $y; $i++) {
408
                            $type    = $finalTokens[$i]['type'];
409
                            $content = PHP_CodeSniffer::prepareForOutput($finalTokens[$i]['content']);
410
                            echo "\tProcess token $i: $type => $content".PHP_EOL;
411
                        }
412
413
                        echo "\t\t* token starts a URL *".PHP_EOL;
414
                    }
415
416
                    // Join all the content together inside the url() statement.
417
                    $newContent = '';
418
                    for ($i = ($x + 2); $i < $numTokens; $i++) {
419
                        if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
420
                            break;
421
                        }
422
423
                        $newContent .= $finalTokens[$i]['content'];
424 View Code Duplication
                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
425
                            $content = PHP_CodeSniffer::prepareForOutput($finalTokens[$i]['content']);
426
                            echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL;
427
                        }
428
429
                        unset($finalTokens[$i]);
430
                    }
431
432
                    $stackPtr = $i;
433
434
                    // If the content inside the "url()" is in double quotes
435
                    // there will only be one token and so we don't have to do
436
                    // anything except change its type. If it is not empty,
437
                    // we need to do some token merging.
438
                    $finalTokens[($x + 1)]['type'] = 'T_URL';
439
                    $finalTokens[($x + 1)]['code'] = T_URL;
440
441
                    if ($newContent !== '') {
442
                        $finalTokens[($x + 1)]['content'] .= $newContent;
443
                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
444
                            $content = PHP_CodeSniffer::prepareForOutput($finalTokens[($x + 1)]['content']);
445
                            echo "\t\t=> token content changed to: $content".PHP_EOL;
446
                        }
447
                    }
448
                }//end if
449
450
                break;
451
            case T_ASPERAND:
452
                $asperandStart = true;
453
                if (PHP_CODESNIFFER_VERBOSITY > 1) {
454
                    echo "\t\t* at-rule definition opened *".PHP_EOL;
455
                }
456
                break;
457
            default:
458
                // Nothing special to be done with this token.
459
                break;
460
            }//end switch
461
        }//end for
462
463
        // Reset the array keys to avoid gaps.
464
        $finalTokens = array_values($finalTokens);
465
        $numTokens   = count($finalTokens);
466
467
        // Blank out the content of the end tag.
468
        $finalTokens[($numTokens - 1)]['content'] = '';
469
470
        if ($eolAdded === true) {
471
            // Strip off the extra EOL char we added for tokenizing.
472
            $finalTokens[($numTokens - 2)]['content'] = substr(
473
                $finalTokens[($numTokens - 2)]['content'],
474
                0,
475
                (strlen($eolChar) * -1)
476
            );
477
478
            if ($finalTokens[($numTokens - 2)]['content'] === '') {
479
                unset($finalTokens[($numTokens - 2)]);
480
                $finalTokens = array_values($finalTokens);
481
                $numTokens   = count($finalTokens);
0 ignored issues
show
Unused Code introduced by
$numTokens is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
482
            }
483
        }
484
485
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
486
            echo "\t*** END CSS TOKENIZING 2ND PASS ***".PHP_EOL;
487
        }
488
489
        return $finalTokens;
490
491
    }//end tokenizeString()
492
493
494
    /**
495
     * Performs additional processing after main tokenizing.
496
     *
497
     * @param array  $tokens  The array of tokens to process.
498
     * @param string $eolChar The EOL character to use for splitting strings.
499
     *
500
     * @return void
501
     */
502
    public function processAdditional(&$tokens, $eolChar)
503
    {
504
        /*
505
            We override this method because we don't want the PHP version to
506
            run during CSS processing because it is wasted processing time.
507
        */
508
509
    }//end processAdditional()
510
511
512
}//end class
513