@@ -21,16 +21,16 @@ |
||
21 | 21 | * @var string[] |
22 | 22 | */ |
23 | 23 | public static $allowedTypes = array( |
24 | - 'array', |
|
25 | - 'boolean', |
|
26 | - 'float', |
|
27 | - 'integer', |
|
28 | - 'mixed', |
|
29 | - 'object', |
|
30 | - 'string', |
|
31 | - 'resource', |
|
32 | - 'callable', |
|
33 | - ); |
|
24 | + 'array', |
|
25 | + 'boolean', |
|
26 | + 'float', |
|
27 | + 'integer', |
|
28 | + 'mixed', |
|
29 | + 'object', |
|
30 | + 'string', |
|
31 | + 'resource', |
|
32 | + 'callable', |
|
33 | + ); |
|
34 | 34 | |
35 | 35 | |
36 | 36 | /** |
@@ -343,15 +343,15 @@ |
||
343 | 343 | } else { |
344 | 344 | $lowerVarType = strtolower($varType); |
345 | 345 | switch ($lowerVarType) { |
346 | - case 'bool': |
|
347 | - return 'boolean'; |
|
348 | - case 'double': |
|
349 | - case 'real': |
|
350 | - return 'float'; |
|
351 | - case 'int': |
|
352 | - return 'integer'; |
|
353 | - case 'array()': |
|
354 | - return 'array'; |
|
346 | + case 'bool': |
|
347 | + return 'boolean'; |
|
348 | + case 'double': |
|
349 | + case 'real': |
|
350 | + return 'float'; |
|
351 | + case 'int': |
|
352 | + return 'integer'; |
|
353 | + case 'array()': |
|
354 | + return 'array'; |
|
355 | 355 | }//end switch |
356 | 356 | |
357 | 357 | if (strpos($lowerVarType, 'array(') !== false) { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - public static function prepareForOutput($content, $exclude=array()) |
|
165 | + public static function prepareForOutput($content, $exclude = array()) |
|
166 | 166 | { |
167 | 167 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
168 | 168 | if (in_array("\r", $exclude) === false) { |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public static function isCamelCaps( |
223 | 223 | $string, |
224 | - $classFormat=false, |
|
225 | - $public=true, |
|
226 | - $strict=true |
|
224 | + $classFormat = false, |
|
225 | + $public = true, |
|
226 | + $strict = true |
|
227 | 227 | ) { |
228 | 228 | // Check the first character first. |
229 | 229 | if ($classFormat === false) { |
@@ -40,7 +40,7 @@ |
||
40 | 40 | * |
41 | 41 | * @param string $path The path to use. |
42 | 42 | * |
43 | - * @return mixed |
|
43 | + * @return string |
|
44 | 44 | */ |
45 | 45 | public static function realpath($path) |
46 | 46 | { |
@@ -9,9 +9,6 @@ |
||
9 | 9 | |
10 | 10 | namespace Symplify\PHP7_CodeSniffer\Util; |
11 | 11 | |
12 | -use Symplify\PHP7_CodeSniffer\Config; |
|
13 | -use Symplify\PHP7_CodeSniffer\Exceptions\RuntimeException; |
|
14 | - |
|
15 | 12 | class Common |
16 | 13 | { |
17 | 14 |
@@ -212,8 +212,8 @@ |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | $replacements = array( |
215 | - '\\,' => ',', |
|
216 | - '*' => '.*', |
|
215 | + '\\,' => ',', |
|
216 | + '*' => '.*', |
|
217 | 217 | ); |
218 | 218 | |
219 | 219 | // We assume a / directory separator, as do the exclude rules |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | $this->reports[$type] = array( |
119 | - 'output' => $output, |
|
120 | - 'class' => $reportClass, |
|
119 | + 'output' => $output, |
|
120 | + 'class' => $reportClass, |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | if ($output === null) { |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | public function prepareFileReport(File $phpcsFile) |
286 | 286 | { |
287 | 287 | $report = array( |
288 | - 'filename' => Common::stripBasepath($phpcsFile->getFilename(), $this->config->basepath), |
|
289 | - 'errors' => $phpcsFile->getErrorCount(), |
|
290 | - 'warnings' => $phpcsFile->getWarningCount(), |
|
291 | - 'fixable' => $phpcsFile->getFixableCount(), |
|
292 | - 'messages' => array(), |
|
293 | - ); |
|
288 | + 'filename' => Common::stripBasepath($phpcsFile->getFilename(), $this->config->basepath), |
|
289 | + 'errors' => $phpcsFile->getErrorCount(), |
|
290 | + 'warnings' => $phpcsFile->getWarningCount(), |
|
291 | + 'fixable' => $phpcsFile->getFixableCount(), |
|
292 | + 'messages' => array(), |
|
293 | + ); |
|
294 | 294 | |
295 | 295 | if ($report['errors'] === 0 && $report['warnings'] === 0) { |
296 | 296 | // Prefect score! |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | $message = 'Errors are not being recorded but this report requires error messages. '; |
302 | 302 | $message .= 'This report will not show the correct information.'; |
303 | 303 | $report['messages'][1][1] = array( |
304 | - array( |
|
305 | - 'message' => $message, |
|
306 | - 'source' => 'Internal.RecordErrors', |
|
307 | - 'severity' => 5, |
|
308 | - 'fixable' => false, |
|
309 | - 'type' => 'ERROR', |
|
310 | - ), |
|
304 | + array( |
|
305 | + 'message' => $message, |
|
306 | + 'source' => 'Internal.RecordErrors', |
|
307 | + 'severity' => 5, |
|
308 | + 'fixable' => false, |
|
309 | + 'type' => 'ERROR', |
|
310 | + ), |
|
311 | 311 | ); |
312 | 312 | return $report; |
313 | 313 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | 'severity' => $data['severity'], |
326 | 326 | 'fixable' => $data['fixable'], |
327 | 327 | 'type' => 'ERROR', |
328 | - ); |
|
328 | + ); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | $errors[$line][$column] = $newErrors; |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | $newWarnings = array(); |
340 | 340 | foreach ($colWarnings as $data) { |
341 | 341 | $newWarnings[] = array( |
342 | - 'message' => $data['message'], |
|
343 | - 'source' => $data['source'], |
|
344 | - 'severity' => $data['severity'], |
|
345 | - 'fixable' => $data['fixable'], |
|
346 | - 'type' => 'WARNING', |
|
347 | - ); |
|
342 | + 'message' => $data['message'], |
|
343 | + 'source' => $data['source'], |
|
344 | + 'severity' => $data['severity'], |
|
345 | + 'fixable' => $data['fixable'], |
|
346 | + 'type' => 'WARNING', |
|
347 | + ); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | if (isset($errors[$line]) === false) { |
@@ -90,37 +90,37 @@ discard block |
||
90 | 90 | * @var array<string, mixed> |
91 | 91 | */ |
92 | 92 | private $settings = array( |
93 | - 'files' => null, |
|
94 | - 'standards' => null, |
|
95 | - 'verbosity' => null, |
|
96 | - 'interactive' => null, |
|
97 | - 'parallel' => null, |
|
98 | - 'cache' => null, |
|
99 | - 'cacheFile' => null, |
|
100 | - 'colors' => null, |
|
101 | - 'explain' => null, |
|
102 | - 'local' => null, |
|
103 | - 'showSources' => null, |
|
104 | - 'showProgress' => null, |
|
105 | - 'tabWidth' => null, |
|
106 | - 'encoding' => null, |
|
107 | - 'extensions' => null, |
|
108 | - 'sniffs' => null, |
|
109 | - 'ignored' => null, |
|
110 | - 'reportFile' => null, |
|
111 | - 'generator' => null, |
|
112 | - 'filter' => null, |
|
113 | - 'bootstrap' => null, |
|
114 | - 'reports' => null, |
|
115 | - 'basepath' => null, |
|
116 | - 'reportWidth' => null, |
|
117 | - 'errorSeverity' => null, |
|
118 | - 'warningSeverity' => null, |
|
119 | - 'recordErrors' => null, |
|
120 | - 'suffix' => null, |
|
121 | - 'stdin' => null, |
|
122 | - 'stdinContent' => null, |
|
123 | - 'stdinPath' => null, |
|
93 | + 'files' => null, |
|
94 | + 'standards' => null, |
|
95 | + 'verbosity' => null, |
|
96 | + 'interactive' => null, |
|
97 | + 'parallel' => null, |
|
98 | + 'cache' => null, |
|
99 | + 'cacheFile' => null, |
|
100 | + 'colors' => null, |
|
101 | + 'explain' => null, |
|
102 | + 'local' => null, |
|
103 | + 'showSources' => null, |
|
104 | + 'showProgress' => null, |
|
105 | + 'tabWidth' => null, |
|
106 | + 'encoding' => null, |
|
107 | + 'extensions' => null, |
|
108 | + 'sniffs' => null, |
|
109 | + 'ignored' => null, |
|
110 | + 'reportFile' => null, |
|
111 | + 'generator' => null, |
|
112 | + 'filter' => null, |
|
113 | + 'bootstrap' => null, |
|
114 | + 'reports' => null, |
|
115 | + 'basepath' => null, |
|
116 | + 'reportWidth' => null, |
|
117 | + 'errorSeverity' => null, |
|
118 | + 'warningSeverity' => null, |
|
119 | + 'recordErrors' => null, |
|
120 | + 'suffix' => null, |
|
121 | + 'stdin' => null, |
|
122 | + 'stdinContent' => null, |
|
123 | + 'stdinPath' => null, |
|
124 | 124 | ); |
125 | 125 | |
126 | 126 | /** |
@@ -417,11 +417,11 @@ discard block |
||
417 | 417 | $this->tabWidth = 0; |
418 | 418 | $this->encoding = 'utf-8'; |
419 | 419 | $this->extensions = array( |
420 | - 'php' => 'PHP', |
|
421 | - 'inc' => 'PHP', |
|
422 | - 'js' => 'JS', |
|
423 | - 'css' => 'CSS', |
|
424 | - ); |
|
420 | + 'php' => 'PHP', |
|
421 | + 'inc' => 'PHP', |
|
422 | + 'js' => 'JS', |
|
423 | + 'css' => 'CSS', |
|
424 | + ); |
|
425 | 425 | $this->sniffs = array(); |
426 | 426 | $this->ignored = array(); |
427 | 427 | $this->reportFile = null; |
@@ -204,35 +204,35 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | switch ($name) { |
207 | - case 'reportWidth' : |
|
208 | - // Support auto terminal width. |
|
209 | - if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
210 | - $value = (int) $matches[1]; |
|
211 | - } else { |
|
212 | - $value = (int) $value; |
|
213 | - } |
|
214 | - break; |
|
215 | - case 'standards' : |
|
216 | - $cleaned = array(); |
|
217 | - |
|
218 | - // Check if the standard name is valid, or if the case is invalid. |
|
219 | - $installedStandards = Util\Standards::getInstalledStandards(); |
|
220 | - foreach ($value as $standard) { |
|
221 | - foreach ($installedStandards as $validStandard) { |
|
222 | - if (strtolower($standard) === strtolower($validStandard)) { |
|
223 | - $standard = $validStandard; |
|
224 | - break; |
|
225 | - } |
|
207 | + case 'reportWidth' : |
|
208 | + // Support auto terminal width. |
|
209 | + if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
210 | + $value = (int) $matches[1]; |
|
211 | + } else { |
|
212 | + $value = (int) $value; |
|
226 | 213 | } |
214 | + break; |
|
215 | + case 'standards' : |
|
216 | + $cleaned = array(); |
|
217 | + |
|
218 | + // Check if the standard name is valid, or if the case is invalid. |
|
219 | + $installedStandards = Util\Standards::getInstalledStandards(); |
|
220 | + foreach ($value as $standard) { |
|
221 | + foreach ($installedStandards as $validStandard) { |
|
222 | + if (strtolower($standard) === strtolower($validStandard)) { |
|
223 | + $standard = $validStandard; |
|
224 | + break; |
|
225 | + } |
|
226 | + } |
|
227 | 227 | |
228 | - $cleaned[] = $standard; |
|
229 | - } |
|
228 | + $cleaned[] = $standard; |
|
229 | + } |
|
230 | 230 | |
231 | - $value = $cleaned; |
|
232 | - break; |
|
233 | - default : |
|
234 | - // No validation required. |
|
235 | - break; |
|
231 | + $value = $cleaned; |
|
232 | + break; |
|
233 | + default : |
|
234 | + // No validation required. |
|
235 | + break; |
|
236 | 236 | }//end switch |
237 | 237 | |
238 | 238 | $this->settings[$name] = $value; |
@@ -523,68 +523,68 @@ discard block |
||
523 | 523 | public function processShortArgument($arg, $pos) |
524 | 524 | { |
525 | 525 | switch ($arg) { |
526 | - case 'h': |
|
527 | - case '?': |
|
528 | - $this->printUsage(); |
|
529 | - exit(0); |
|
530 | - case 'i' : |
|
531 | - Util\Standards::printInstalledStandards(); |
|
532 | - exit(0); |
|
533 | - case 'v' : |
|
534 | - $this->verbosity++; |
|
535 | - $this->overriddenDefaults['verbosity'] = true; |
|
536 | - break; |
|
537 | - case 'l' : |
|
538 | - $this->local = true; |
|
539 | - $this->overriddenDefaults['local'] = true; |
|
540 | - break; |
|
541 | - case 's' : |
|
542 | - $this->showSources = true; |
|
543 | - $this->overriddenDefaults['showSources'] = true; |
|
544 | - break; |
|
545 | - case 'a' : |
|
546 | - $this->interactive = true; |
|
547 | - $this->overriddenDefaults['interactive'] = true; |
|
548 | - break; |
|
549 | - case 'e': |
|
550 | - $this->explain = true; |
|
551 | - $this->overriddenDefaults['explain'] = true; |
|
552 | - break; |
|
553 | - case 'p' : |
|
554 | - $this->showProgress = true; |
|
555 | - $this->overriddenDefaults['showProgress'] = true; |
|
556 | - break; |
|
557 | - case 'm' : |
|
558 | - $this->recordErrors = false; |
|
559 | - $this->overriddenDefaults['recordErrors'] = true; |
|
560 | - break; |
|
561 | - case 'd' : |
|
562 | - $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
563 | - $this->cliArgs[($pos + 1)] = ''; |
|
564 | - if (isset($ini[1]) === true) { |
|
565 | - ini_set($ini[0], $ini[1]); |
|
566 | - } else { |
|
567 | - ini_set($ini[0], true); |
|
568 | - } |
|
569 | - break; |
|
570 | - case 'n' : |
|
571 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
572 | - $this->warningSeverity = 0; |
|
573 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
574 | - } |
|
575 | - break; |
|
576 | - case 'w' : |
|
577 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
578 | - $this->warningSeverity = $this->errorSeverity; |
|
579 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
580 | - } |
|
581 | - break; |
|
582 | - default: |
|
583 | - if ($this->dieOnUnknownArg === false) { |
|
584 | - $this->values[$arg] = $arg; |
|
585 | - } else { |
|
586 | - $this->processUnknownArgument('-'.$arg, $pos); |
|
587 | - } |
|
526 | + case 'h': |
|
527 | + case '?': |
|
528 | + $this->printUsage(); |
|
529 | + exit(0); |
|
530 | + case 'i' : |
|
531 | + Util\Standards::printInstalledStandards(); |
|
532 | + exit(0); |
|
533 | + case 'v' : |
|
534 | + $this->verbosity++; |
|
535 | + $this->overriddenDefaults['verbosity'] = true; |
|
536 | + break; |
|
537 | + case 'l' : |
|
538 | + $this->local = true; |
|
539 | + $this->overriddenDefaults['local'] = true; |
|
540 | + break; |
|
541 | + case 's' : |
|
542 | + $this->showSources = true; |
|
543 | + $this->overriddenDefaults['showSources'] = true; |
|
544 | + break; |
|
545 | + case 'a' : |
|
546 | + $this->interactive = true; |
|
547 | + $this->overriddenDefaults['interactive'] = true; |
|
548 | + break; |
|
549 | + case 'e': |
|
550 | + $this->explain = true; |
|
551 | + $this->overriddenDefaults['explain'] = true; |
|
552 | + break; |
|
553 | + case 'p' : |
|
554 | + $this->showProgress = true; |
|
555 | + $this->overriddenDefaults['showProgress'] = true; |
|
556 | + break; |
|
557 | + case 'm' : |
|
558 | + $this->recordErrors = false; |
|
559 | + $this->overriddenDefaults['recordErrors'] = true; |
|
560 | + break; |
|
561 | + case 'd' : |
|
562 | + $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
563 | + $this->cliArgs[($pos + 1)] = ''; |
|
564 | + if (isset($ini[1]) === true) { |
|
565 | + ini_set($ini[0], $ini[1]); |
|
566 | + } else { |
|
567 | + ini_set($ini[0], true); |
|
568 | + } |
|
569 | + break; |
|
570 | + case 'n' : |
|
571 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
572 | + $this->warningSeverity = 0; |
|
573 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
574 | + } |
|
575 | + break; |
|
576 | + case 'w' : |
|
577 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
578 | + $this->warningSeverity = $this->errorSeverity; |
|
579 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
580 | + } |
|
581 | + break; |
|
582 | + default: |
|
583 | + if ($this->dieOnUnknownArg === false) { |
|
584 | + $this->values[$arg] = $arg; |
|
585 | + } else { |
|
586 | + $this->processUnknownArgument('-'.$arg, $pos); |
|
587 | + } |
|
588 | 588 | }//end switch |
589 | 589 | |
590 | 590 | }//end processShortArgument() |
@@ -601,383 +601,383 @@ discard block |
||
601 | 601 | public function processLongArgument($arg, $pos) |
602 | 602 | { |
603 | 603 | switch ($arg) { |
604 | - case 'help': |
|
605 | - $this->printUsage(); |
|
606 | - exit(0); |
|
607 | - case 'version': |
|
608 | - echo 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') '; |
|
609 | - echo 'by Squiz (http://www.squiz.net)'.PHP_EOL; |
|
610 | - exit(0); |
|
611 | - case 'colors': |
|
612 | - $this->colors = true; |
|
613 | - $this->overriddenDefaults['colors'] = true; |
|
614 | - break; |
|
615 | - case 'no-colors': |
|
616 | - $this->colors = false; |
|
617 | - $this->overriddenDefaults['colors'] = true; |
|
618 | - break; |
|
619 | - case 'cache': |
|
620 | - if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
621 | - $this->cache = true; |
|
622 | - $this->overriddenDefaults['cache'] = true; |
|
623 | - } |
|
624 | - break; |
|
625 | - case 'no-cache': |
|
626 | - $this->cache = false; |
|
627 | - $this->overriddenDefaults['cache'] = true; |
|
628 | - break; |
|
629 | - case 'config-set': |
|
630 | - if (isset($this->cliArgs[($pos + 1)]) === false |
|
631 | - || isset($this->cliArgs[($pos + 2)]) === false |
|
632 | - ) { |
|
633 | - echo 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
604 | + case 'help': |
|
634 | 605 | $this->printUsage(); |
635 | 606 | exit(0); |
636 | - } |
|
637 | - |
|
638 | - $key = $this->cliArgs[($pos + 1)]; |
|
639 | - $value = $this->cliArgs[($pos + 2)]; |
|
640 | - $current = self::getConfigData($key); |
|
641 | - |
|
642 | - try { |
|
643 | - $this->setConfigData($key, $value); |
|
644 | - } catch (Exception $e) { |
|
645 | - echo $e->getMessage().PHP_EOL; |
|
646 | - exit(2); |
|
647 | - } |
|
648 | - |
|
649 | - if ($current === null) { |
|
650 | - echo "Config value \"$key\" added successfully".PHP_EOL; |
|
651 | - } else { |
|
652 | - echo "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL; |
|
653 | - } |
|
654 | - exit(0); |
|
655 | - case 'config-delete': |
|
656 | - if (isset($this->cliArgs[($pos + 1)]) === false) { |
|
657 | - echo 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL; |
|
658 | - $this->printUsage(); |
|
607 | + case 'version': |
|
608 | + echo 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') '; |
|
609 | + echo 'by Squiz (http://www.squiz.net)'.PHP_EOL; |
|
659 | 610 | exit(0); |
660 | - } |
|
611 | + case 'colors': |
|
612 | + $this->colors = true; |
|
613 | + $this->overriddenDefaults['colors'] = true; |
|
614 | + break; |
|
615 | + case 'no-colors': |
|
616 | + $this->colors = false; |
|
617 | + $this->overriddenDefaults['colors'] = true; |
|
618 | + break; |
|
619 | + case 'cache': |
|
620 | + if (defined('PHP_CODESNIFFER_IN_TESTS') === false) { |
|
621 | + $this->cache = true; |
|
622 | + $this->overriddenDefaults['cache'] = true; |
|
623 | + } |
|
624 | + break; |
|
625 | + case 'no-cache': |
|
626 | + $this->cache = false; |
|
627 | + $this->overriddenDefaults['cache'] = true; |
|
628 | + break; |
|
629 | + case 'config-set': |
|
630 | + if (isset($this->cliArgs[($pos + 1)]) === false |
|
631 | + || isset($this->cliArgs[($pos + 2)]) === false |
|
632 | + ) { |
|
633 | + echo 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
634 | + $this->printUsage(); |
|
635 | + exit(0); |
|
636 | + } |
|
637 | + |
|
638 | + $key = $this->cliArgs[($pos + 1)]; |
|
639 | + $value = $this->cliArgs[($pos + 2)]; |
|
640 | + $current = self::getConfigData($key); |
|
661 | 641 | |
662 | - $key = $this->cliArgs[($pos + 1)]; |
|
663 | - $current = self::getConfigData($key); |
|
664 | - if ($current === null) { |
|
665 | - echo "Config value \"$key\" has not been set".PHP_EOL; |
|
666 | - } else { |
|
667 | 642 | try { |
668 | - $this->setConfigData($key, null); |
|
643 | + $this->setConfigData($key, $value); |
|
669 | 644 | } catch (Exception $e) { |
670 | 645 | echo $e->getMessage().PHP_EOL; |
671 | 646 | exit(2); |
672 | 647 | } |
673 | 648 | |
674 | - echo "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL; |
|
675 | - } |
|
676 | - exit(0); |
|
677 | - case 'config-show': |
|
678 | - $data = self::getAllConfigData(); |
|
679 | - $this->printConfigData($data); |
|
680 | - exit(0); |
|
681 | - case 'runtime-set': |
|
682 | - if (isset($this->cliArgs[($pos + 1)]) === false |
|
683 | - || isset($this->cliArgs[($pos + 2)]) === false |
|
684 | - ) { |
|
685 | - echo 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
686 | - $this->printUsage(); |
|
649 | + if ($current === null) { |
|
650 | + echo "Config value \"$key\" added successfully".PHP_EOL; |
|
651 | + } else { |
|
652 | + echo "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL; |
|
653 | + } |
|
687 | 654 | exit(0); |
688 | - } |
|
655 | + case 'config-delete': |
|
656 | + if (isset($this->cliArgs[($pos + 1)]) === false) { |
|
657 | + echo 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL; |
|
658 | + $this->printUsage(); |
|
659 | + exit(0); |
|
660 | + } |
|
689 | 661 | |
690 | - $key = $this->cliArgs[($pos + 1)]; |
|
691 | - $value = $this->cliArgs[($pos + 2)]; |
|
692 | - $this->cliArgs[($pos + 1)] = ''; |
|
693 | - $this->cliArgs[($pos + 2)] = ''; |
|
694 | - self::setConfigData($key, $value, true); |
|
695 | - break; |
|
696 | - default: |
|
697 | - if (substr($arg, 0, 7) === 'sniffs=') { |
|
698 | - $sniffs = explode(',', substr($arg, 7)); |
|
699 | - foreach ($sniffs as $sniff) { |
|
700 | - if (substr_count($sniff, '.') !== 2) { |
|
701 | - echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
702 | - $this->printUsage(); |
|
662 | + $key = $this->cliArgs[($pos + 1)]; |
|
663 | + $current = self::getConfigData($key); |
|
664 | + if ($current === null) { |
|
665 | + echo "Config value \"$key\" has not been set".PHP_EOL; |
|
666 | + } else { |
|
667 | + try { |
|
668 | + $this->setConfigData($key, null); |
|
669 | + } catch (Exception $e) { |
|
670 | + echo $e->getMessage().PHP_EOL; |
|
703 | 671 | exit(2); |
704 | 672 | } |
673 | + |
|
674 | + echo "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL; |
|
675 | + } |
|
676 | + exit(0); |
|
677 | + case 'config-show': |
|
678 | + $data = self::getAllConfigData(); |
|
679 | + $this->printConfigData($data); |
|
680 | + exit(0); |
|
681 | + case 'runtime-set': |
|
682 | + if (isset($this->cliArgs[($pos + 1)]) === false |
|
683 | + || isset($this->cliArgs[($pos + 2)]) === false |
|
684 | + ) { |
|
685 | + echo 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL; |
|
686 | + $this->printUsage(); |
|
687 | + exit(0); |
|
705 | 688 | } |
706 | 689 | |
707 | - $this->sniffs = $sniffs; |
|
708 | - $this->overriddenDefaults['sniffs'] = true; |
|
709 | - } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false |
|
710 | - && substr($arg, 0, 6) === 'cache=' |
|
711 | - ) { |
|
712 | - // Turn caching on. |
|
713 | - $this->cache = true; |
|
714 | - $this->overriddenDefaults['cache'] = true; |
|
690 | + $key = $this->cliArgs[($pos + 1)]; |
|
691 | + $value = $this->cliArgs[($pos + 2)]; |
|
692 | + $this->cliArgs[($pos + 1)] = ''; |
|
693 | + $this->cliArgs[($pos + 2)] = ''; |
|
694 | + self::setConfigData($key, $value, true); |
|
695 | + break; |
|
696 | + default: |
|
697 | + if (substr($arg, 0, 7) === 'sniffs=') { |
|
698 | + $sniffs = explode(',', substr($arg, 7)); |
|
699 | + foreach ($sniffs as $sniff) { |
|
700 | + if (substr_count($sniff, '.') !== 2) { |
|
701 | + echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
702 | + $this->printUsage(); |
|
703 | + exit(2); |
|
704 | + } |
|
705 | + } |
|
715 | 706 | |
716 | - $this->cacheFile = Util\Common::realpath(substr($arg, 6)); |
|
707 | + $this->sniffs = $sniffs; |
|
708 | + $this->overriddenDefaults['sniffs'] = true; |
|
709 | + } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false |
|
710 | + && substr($arg, 0, 6) === 'cache=' |
|
711 | + ) { |
|
712 | + // Turn caching on. |
|
713 | + $this->cache = true; |
|
714 | + $this->overriddenDefaults['cache'] = true; |
|
715 | + |
|
716 | + $this->cacheFile = Util\Common::realpath(substr($arg, 6)); |
|
717 | + |
|
718 | + // It may not exist and return false instead. |
|
719 | + if ($this->cacheFile === false) { |
|
720 | + $this->cacheFile = substr($arg, 6); |
|
721 | + |
|
722 | + $dir = dirname($this->cacheFile); |
|
723 | + if (is_dir($dir) === false) { |
|
724 | + echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
725 | + $this->printUsage(); |
|
726 | + exit(2); |
|
727 | + } |
|
717 | 728 | |
718 | - // It may not exist and return false instead. |
|
719 | - if ($this->cacheFile === false) { |
|
720 | - $this->cacheFile = substr($arg, 6); |
|
729 | + if ($dir === '.') { |
|
730 | + // Passed report file is a file in the current directory. |
|
731 | + $this->cacheFile = getcwd().'/'.basename($this->cacheFile); |
|
732 | + } else { |
|
733 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
734 | + if ($dir !== false) { |
|
735 | + // Report file path is relative. |
|
736 | + $this->cacheFile = $dir.'/'.basename($this->cacheFile); |
|
737 | + } |
|
738 | + } |
|
739 | + }//end if |
|
721 | 740 | |
722 | - $dir = dirname($this->cacheFile); |
|
723 | - if (is_dir($dir) === false) { |
|
724 | - echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
741 | + $this->overriddenDefaults['cacheFile'] = true; |
|
742 | + |
|
743 | + if (is_dir($this->cacheFile) === true) { |
|
744 | + echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
725 | 745 | $this->printUsage(); |
726 | 746 | exit(2); |
727 | 747 | } |
728 | - |
|
729 | - if ($dir === '.') { |
|
730 | - // Passed report file is a file in the current directory. |
|
731 | - $this->cacheFile = getcwd().'/'.basename($this->cacheFile); |
|
732 | - } else { |
|
733 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
734 | - if ($dir !== false) { |
|
735 | - // Report file path is relative. |
|
736 | - $this->cacheFile = $dir.'/'.basename($this->cacheFile); |
|
748 | + } else if (substr($arg, 0, 10) === 'bootstrap=') { |
|
749 | + $files = explode(',', substr($arg, 10)); |
|
750 | + $bootstrap = array(); |
|
751 | + foreach ($files as $file) { |
|
752 | + $path = Util\Common::realpath($file); |
|
753 | + if ($path === false) { |
|
754 | + echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; |
|
755 | + $this->printUsage(); |
|
756 | + exit(2); |
|
737 | 757 | } |
758 | + |
|
759 | + $bootstrap[] = $path; |
|
738 | 760 | } |
739 | - }//end if |
|
740 | 761 | |
741 | - $this->overriddenDefaults['cacheFile'] = true; |
|
762 | + $this->bootstrap = array_merge($this->bootstrap, $bootstrap); |
|
763 | + $this->overriddenDefaults['bootstrap'] = true; |
|
764 | + } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
765 | + $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
742 | 766 | |
743 | - if (is_dir($this->cacheFile) === true) { |
|
744 | - echo 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
745 | - $this->printUsage(); |
|
746 | - exit(2); |
|
747 | - } |
|
748 | - } else if (substr($arg, 0, 10) === 'bootstrap=') { |
|
749 | - $files = explode(',', substr($arg, 10)); |
|
750 | - $bootstrap = array(); |
|
751 | - foreach ($files as $file) { |
|
752 | - $path = Util\Common::realpath($file); |
|
753 | - if ($path === false) { |
|
754 | - echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; |
|
755 | - $this->printUsage(); |
|
756 | - exit(2); |
|
767 | + // It may not exist and return false instead, so use whatever they gave us. |
|
768 | + if ($this->stdinPath === false) { |
|
769 | + $this->stdinPath = trim(substr($arg, 11)); |
|
757 | 770 | } |
758 | 771 | |
759 | - $bootstrap[] = $path; |
|
760 | - } |
|
772 | + $this->overriddenDefaults['stdinPath'] = true; |
|
773 | + } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') { |
|
774 | + $this->reportFile = Util\Common::realpath(substr($arg, 12)); |
|
761 | 775 | |
762 | - $this->bootstrap = array_merge($this->bootstrap, $bootstrap); |
|
763 | - $this->overriddenDefaults['bootstrap'] = true; |
|
764 | - } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
765 | - $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
776 | + // It may not exist and return false instead. |
|
777 | + if ($this->reportFile === false) { |
|
778 | + $this->reportFile = substr($arg, 12); |
|
766 | 779 | |
767 | - // It may not exist and return false instead, so use whatever they gave us. |
|
768 | - if ($this->stdinPath === false) { |
|
769 | - $this->stdinPath = trim(substr($arg, 11)); |
|
770 | - } |
|
780 | + $dir = dirname($this->reportFile); |
|
781 | + if (is_dir($dir) === false) { |
|
782 | + echo 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
783 | + $this->printUsage(); |
|
784 | + exit(2); |
|
785 | + } |
|
771 | 786 | |
772 | - $this->overriddenDefaults['stdinPath'] = true; |
|
773 | - } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') { |
|
774 | - $this->reportFile = Util\Common::realpath(substr($arg, 12)); |
|
787 | + if ($dir === '.') { |
|
788 | + // Passed report file is a file in the current directory. |
|
789 | + $this->reportFile = getcwd().'/'.basename($this->reportFile); |
|
790 | + } else { |
|
791 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
792 | + if ($dir !== false) { |
|
793 | + // Report file path is relative. |
|
794 | + $this->reportFile = $dir.'/'.basename($this->reportFile); |
|
795 | + } |
|
796 | + } |
|
797 | + }//end if |
|
775 | 798 | |
776 | - // It may not exist and return false instead. |
|
777 | - if ($this->reportFile === false) { |
|
778 | - $this->reportFile = substr($arg, 12); |
|
799 | + $this->overriddenDefaults['reportFile'] = true; |
|
779 | 800 | |
780 | - $dir = dirname($this->reportFile); |
|
781 | - if (is_dir($dir) === false) { |
|
782 | - echo 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
801 | + if (is_dir($this->reportFile) === true) { |
|
802 | + echo 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
783 | 803 | $this->printUsage(); |
784 | 804 | exit(2); |
785 | 805 | } |
786 | - |
|
787 | - if ($dir === '.') { |
|
788 | - // Passed report file is a file in the current directory. |
|
789 | - $this->reportFile = getcwd().'/'.basename($this->reportFile); |
|
790 | - } else { |
|
791 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
792 | - if ($dir !== false) { |
|
793 | - // Report file path is relative. |
|
794 | - $this->reportFile = $dir.'/'.basename($this->reportFile); |
|
795 | - } |
|
806 | + } else if (substr($arg, 0, 13) === 'report-width=') { |
|
807 | + if (isset($this->overriddenDefaults['reportWidth']) === true) { |
|
808 | + break; |
|
796 | 809 | } |
797 | - }//end if |
|
798 | - |
|
799 | - $this->overriddenDefaults['reportFile'] = true; |
|
800 | 810 | |
801 | - if (is_dir($this->reportFile) === true) { |
|
802 | - echo 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL; |
|
803 | - $this->printUsage(); |
|
804 | - exit(2); |
|
805 | - } |
|
806 | - } else if (substr($arg, 0, 13) === 'report-width=') { |
|
807 | - if (isset($this->overriddenDefaults['reportWidth']) === true) { |
|
808 | - break; |
|
809 | - } |
|
810 | - |
|
811 | - $this->reportWidth = substr($arg, 13); |
|
812 | - $this->overriddenDefaults['reportWidth'] = true; |
|
813 | - } else if (substr($arg, 0, 9) === 'basepath=') { |
|
814 | - if (isset($this->overriddenDefaults['basepath']) === true) { |
|
815 | - break; |
|
816 | - } |
|
811 | + $this->reportWidth = substr($arg, 13); |
|
812 | + $this->overriddenDefaults['reportWidth'] = true; |
|
813 | + } else if (substr($arg, 0, 9) === 'basepath=') { |
|
814 | + if (isset($this->overriddenDefaults['basepath']) === true) { |
|
815 | + break; |
|
816 | + } |
|
817 | 817 | |
818 | - $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
818 | + $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
819 | 819 | |
820 | - // It may not exist and return false instead. |
|
821 | - if ($this->basepath === false) { |
|
822 | - $this->basepath = substr($arg, 9); |
|
823 | - } |
|
820 | + // It may not exist and return false instead. |
|
821 | + if ($this->basepath === false) { |
|
822 | + $this->basepath = substr($arg, 9); |
|
823 | + } |
|
824 | 824 | |
825 | - $this->overriddenDefaults['basepath'] = true; |
|
825 | + $this->overriddenDefaults['basepath'] = true; |
|
826 | 826 | |
827 | - if (is_dir($this->basepath) === false) { |
|
828 | - echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
829 | - $this->printUsage(); |
|
830 | - exit(2); |
|
831 | - } |
|
832 | - } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) { |
|
833 | - $reports = array(); |
|
834 | - |
|
835 | - if ($arg[6] === '-') { |
|
836 | - // This is a report with file output. |
|
837 | - $split = strpos($arg, '='); |
|
838 | - if ($split === false) { |
|
839 | - $report = substr($arg, 7); |
|
840 | - $output = null; |
|
841 | - } else { |
|
842 | - $report = substr($arg, 7, ($split - 7)); |
|
843 | - $output = substr($arg, ($split + 1)); |
|
844 | - if ($output === false) { |
|
827 | + if (is_dir($this->basepath) === false) { |
|
828 | + echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
829 | + $this->printUsage(); |
|
830 | + exit(2); |
|
831 | + } |
|
832 | + } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) { |
|
833 | + $reports = array(); |
|
834 | + |
|
835 | + if ($arg[6] === '-') { |
|
836 | + // This is a report with file output. |
|
837 | + $split = strpos($arg, '='); |
|
838 | + if ($split === false) { |
|
839 | + $report = substr($arg, 7); |
|
845 | 840 | $output = null; |
846 | 841 | } else { |
847 | - $dir = dirname($output); |
|
848 | - if ($dir === '.') { |
|
849 | - // Passed report file is a filename in the current directory. |
|
850 | - $output = getcwd().'/'.basename($output); |
|
842 | + $report = substr($arg, 7, ($split - 7)); |
|
843 | + $output = substr($arg, ($split + 1)); |
|
844 | + if ($output === false) { |
|
845 | + $output = null; |
|
851 | 846 | } else { |
852 | - $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
853 | - if ($dir !== false) { |
|
854 | - // Report file path is relative. |
|
855 | - $output = $dir.'/'.basename($output); |
|
847 | + $dir = dirname($output); |
|
848 | + if ($dir === '.') { |
|
849 | + // Passed report file is a filename in the current directory. |
|
850 | + $output = getcwd().'/'.basename($output); |
|
851 | + } else { |
|
852 | + $dir = Util\Common::realpath(getcwd().'/'.$dir); |
|
853 | + if ($dir !== false) { |
|
854 | + // Report file path is relative. |
|
855 | + $output = $dir.'/'.basename($output); |
|
856 | + } |
|
856 | 857 | } |
857 | - } |
|
858 | + }//end if |
|
858 | 859 | }//end if |
860 | + |
|
861 | + $reports[$report] = $output; |
|
862 | + } else { |
|
863 | + // This is a single report. |
|
864 | + if (isset($this->overriddenDefaults['reports']) === true) { |
|
865 | + break; |
|
866 | + } |
|
867 | + |
|
868 | + $reportNames = explode(',', substr($arg, 7)); |
|
869 | + foreach ($reportNames as $report) { |
|
870 | + $reports[$report] = null; |
|
871 | + } |
|
859 | 872 | }//end if |
860 | 873 | |
861 | - $reports[$report] = $output; |
|
862 | - } else { |
|
863 | - // This is a single report. |
|
864 | - if (isset($this->overriddenDefaults['reports']) === true) { |
|
865 | - break; |
|
874 | + // Remove the default value so the CLI value overrides it. |
|
875 | + if (isset($this->overriddenDefaults['reports']) === false) { |
|
876 | + $this->reports = $reports; |
|
877 | + } else { |
|
878 | + $this->reports = array_merge($this->reports, $reports); |
|
866 | 879 | } |
867 | 880 | |
868 | - $reportNames = explode(',', substr($arg, 7)); |
|
869 | - foreach ($reportNames as $report) { |
|
870 | - $reports[$report] = null; |
|
881 | + $this->overriddenDefaults['reports'] = true; |
|
882 | + } else if (substr($arg, 0, 7) === 'filter=') { |
|
883 | + if (isset($this->overriddenDefaults['filter']) === true) { |
|
884 | + break; |
|
871 | 885 | } |
872 | - }//end if |
|
873 | 886 | |
874 | - // Remove the default value so the CLI value overrides it. |
|
875 | - if (isset($this->overriddenDefaults['reports']) === false) { |
|
876 | - $this->reports = $reports; |
|
877 | - } else { |
|
878 | - $this->reports = array_merge($this->reports, $reports); |
|
879 | - } |
|
880 | - |
|
881 | - $this->overriddenDefaults['reports'] = true; |
|
882 | - } else if (substr($arg, 0, 7) === 'filter=') { |
|
883 | - if (isset($this->overriddenDefaults['filter']) === true) { |
|
884 | - break; |
|
885 | - } |
|
887 | + $this->filter = substr($arg, 7); |
|
888 | + $this->overriddenDefaults['filter'] = true; |
|
889 | + } else if (substr($arg, 0, 9) === 'standard=') { |
|
890 | + $standards = trim(substr($arg, 9)); |
|
891 | + if ($standards !== '') { |
|
892 | + $this->standards = explode(',', $standards); |
|
893 | + } |
|
886 | 894 | |
887 | - $this->filter = substr($arg, 7); |
|
888 | - $this->overriddenDefaults['filter'] = true; |
|
889 | - } else if (substr($arg, 0, 9) === 'standard=') { |
|
890 | - $standards = trim(substr($arg, 9)); |
|
891 | - if ($standards !== '') { |
|
892 | - $this->standards = explode(',', $standards); |
|
893 | - } |
|
895 | + $this->overriddenDefaults['standards'] = true; |
|
896 | + } else if (substr($arg, 0, 11) === 'extensions=') { |
|
897 | + $extensions = explode(',', substr($arg, 11)); |
|
898 | + $newExtensions = array(); |
|
899 | + foreach ($extensions as $ext) { |
|
900 | + $slash = strpos($ext, '/'); |
|
901 | + if ($slash !== false) { |
|
902 | + // They specified the tokenizer too. |
|
903 | + list($ext, $tokenizer) = explode('/', $ext); |
|
904 | + $newExtensions[$ext] = strtoupper($tokenizer); |
|
905 | + continue; |
|
906 | + } |
|
894 | 907 | |
895 | - $this->overriddenDefaults['standards'] = true; |
|
896 | - } else if (substr($arg, 0, 11) === 'extensions=') { |
|
897 | - $extensions = explode(',', substr($arg, 11)); |
|
898 | - $newExtensions = array(); |
|
899 | - foreach ($extensions as $ext) { |
|
900 | - $slash = strpos($ext, '/'); |
|
901 | - if ($slash !== false) { |
|
902 | - // They specified the tokenizer too. |
|
903 | - list($ext, $tokenizer) = explode('/', $ext); |
|
904 | - $newExtensions[$ext] = strtoupper($tokenizer); |
|
905 | - continue; |
|
908 | + if (isset($this->extensions[$ext]) === true) { |
|
909 | + $newExtensions[$ext] = $this->extensions[$ext]; |
|
910 | + } else { |
|
911 | + $newExtensions[$ext] = 'PHP'; |
|
912 | + } |
|
906 | 913 | } |
907 | 914 | |
908 | - if (isset($this->extensions[$ext]) === true) { |
|
909 | - $newExtensions[$ext] = $this->extensions[$ext]; |
|
910 | - } else { |
|
911 | - $newExtensions[$ext] = 'PHP'; |
|
912 | - } |
|
913 | - } |
|
915 | + $this->extensions = $newExtensions; |
|
916 | + $this->overriddenDefaults['extensions'] = true; |
|
917 | + } else if (substr($arg, 0, 7) === 'suffix=') { |
|
918 | + $this->suffix = explode(',', substr($arg, 7)); |
|
919 | + $this->overriddenDefaults['suffix'] = true; |
|
920 | + } else if (substr($arg, 0, 9) === 'parallel=') { |
|
921 | + $this->parallel = max((int) substr($arg, 9), 1); |
|
922 | + $this->overriddenDefaults['parallel'] = true; |
|
923 | + } else if (substr($arg, 0, 9) === 'severity=') { |
|
924 | + $this->errorSeverity = (int) substr($arg, 9); |
|
925 | + $this->warningSeverity = $this->errorSeverity; |
|
926 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
927 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
928 | + } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
929 | + $this->errorSeverity = (int) substr($arg, 15); |
|
930 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
931 | + } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
932 | + $this->warningSeverity = (int) substr($arg, 17); |
|
933 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
934 | + } else if (substr($arg, 0, 7) === 'ignore=') { |
|
935 | + // Split the ignore string on commas, unless the comma is escaped |
|
936 | + // using 1 or 3 slashes (\, or \\\,). |
|
937 | + $patterns = preg_split( |
|
938 | + '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
939 | + substr($arg, 7) |
|
940 | + ); |
|
941 | + |
|
942 | + $ignored = array(); |
|
943 | + foreach ($patterns as $pattern) { |
|
944 | + $pattern = trim($pattern); |
|
945 | + if ($pattern === '') { |
|
946 | + continue; |
|
947 | + } |
|
914 | 948 | |
915 | - $this->extensions = $newExtensions; |
|
916 | - $this->overriddenDefaults['extensions'] = true; |
|
917 | - } else if (substr($arg, 0, 7) === 'suffix=') { |
|
918 | - $this->suffix = explode(',', substr($arg, 7)); |
|
919 | - $this->overriddenDefaults['suffix'] = true; |
|
920 | - } else if (substr($arg, 0, 9) === 'parallel=') { |
|
921 | - $this->parallel = max((int) substr($arg, 9), 1); |
|
922 | - $this->overriddenDefaults['parallel'] = true; |
|
923 | - } else if (substr($arg, 0, 9) === 'severity=') { |
|
924 | - $this->errorSeverity = (int) substr($arg, 9); |
|
925 | - $this->warningSeverity = $this->errorSeverity; |
|
926 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
927 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
928 | - } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
929 | - $this->errorSeverity = (int) substr($arg, 15); |
|
930 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
931 | - } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
932 | - $this->warningSeverity = (int) substr($arg, 17); |
|
933 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
934 | - } else if (substr($arg, 0, 7) === 'ignore=') { |
|
935 | - // Split the ignore string on commas, unless the comma is escaped |
|
936 | - // using 1 or 3 slashes (\, or \\\,). |
|
937 | - $patterns = preg_split( |
|
938 | - '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
939 | - substr($arg, 7) |
|
940 | - ); |
|
941 | - |
|
942 | - $ignored = array(); |
|
943 | - foreach ($patterns as $pattern) { |
|
944 | - $pattern = trim($pattern); |
|
945 | - if ($pattern === '') { |
|
946 | - continue; |
|
949 | + $ignored[$pattern] = 'absolute'; |
|
947 | 950 | } |
948 | 951 | |
949 | - $ignored[$pattern] = 'absolute'; |
|
950 | - } |
|
951 | - |
|
952 | - $this->ignored = $ignored; |
|
953 | - $this->overriddenDefaults['ignored'] = true; |
|
954 | - } else if (substr($arg, 0, 10) === 'generator=' |
|
955 | - && PHP_CODESNIFFER_CBF === false |
|
956 | - ) { |
|
957 | - $this->generator = substr($arg, 10); |
|
958 | - $this->overriddenDefaults['generator'] = true; |
|
959 | - } else if (substr($arg, 0, 9) === 'encoding=') { |
|
960 | - $this->encoding = strtolower(substr($arg, 9)); |
|
961 | - $this->overriddenDefaults['encoding'] = true; |
|
962 | - } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
963 | - $this->tabWidth = (int) substr($arg, 10); |
|
964 | - $this->overriddenDefaults['tabWidth'] = true; |
|
965 | - } else { |
|
966 | - if ($this->dieOnUnknownArg === false) { |
|
967 | - $eqPos = strpos($arg, '='); |
|
968 | - if ($eqPos === false) { |
|
969 | - $this->values[$arg] = $arg; |
|
952 | + $this->ignored = $ignored; |
|
953 | + $this->overriddenDefaults['ignored'] = true; |
|
954 | + } else if (substr($arg, 0, 10) === 'generator=' |
|
955 | + && PHP_CODESNIFFER_CBF === false |
|
956 | + ) { |
|
957 | + $this->generator = substr($arg, 10); |
|
958 | + $this->overriddenDefaults['generator'] = true; |
|
959 | + } else if (substr($arg, 0, 9) === 'encoding=') { |
|
960 | + $this->encoding = strtolower(substr($arg, 9)); |
|
961 | + $this->overriddenDefaults['encoding'] = true; |
|
962 | + } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
963 | + $this->tabWidth = (int) substr($arg, 10); |
|
964 | + $this->overriddenDefaults['tabWidth'] = true; |
|
965 | + } else { |
|
966 | + if ($this->dieOnUnknownArg === false) { |
|
967 | + $eqPos = strpos($arg, '='); |
|
968 | + if ($eqPos === false) { |
|
969 | + $this->values[$arg] = $arg; |
|
970 | + } else { |
|
971 | + $value = substr($arg, ($eqPos + 1)); |
|
972 | + $arg = substr($arg, 0, $eqPos); |
|
973 | + $this->values[$arg] = $value; |
|
974 | + } |
|
970 | 975 | } else { |
971 | - $value = substr($arg, ($eqPos + 1)); |
|
972 | - $arg = substr($arg, 0, $eqPos); |
|
973 | - $this->values[$arg] = $value; |
|
976 | + $this->processUnknownArgument('--'.$arg, $pos); |
|
974 | 977 | } |
975 | - } else { |
|
976 | - $this->processUnknownArgument('--'.$arg, $pos); |
|
977 | - } |
|
978 | - }//end if |
|
978 | + }//end if |
|
979 | 979 | |
980 | - break; |
|
980 | + break; |
|
981 | 981 | }//end switch |
982 | 982 | |
983 | 983 | }//end processLongArgument() |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return void |
279 | 279 | */ |
280 | - public function __construct(array $cliArgs=array(), $dieOnUnknownArg=true) |
|
280 | + public function __construct(array $cliArgs = array(), $dieOnUnknownArg = true) |
|
281 | 281 | { |
282 | 282 | if (defined('PHP_CODESNIFFER_IN_TESTS') === true) { |
283 | 283 | // Let everything through during testing so that we can |
@@ -1224,7 +1224,7 @@ discard block |
||
1224 | 1224 | * @see getConfigData() |
1225 | 1225 | * @throws RuntimeException If the config file can not be written. |
1226 | 1226 | */ |
1227 | - public static function setConfigData($key, $value, $temp=false) |
|
1227 | + public static function setConfigData($key, $value, $temp = false) |
|
1228 | 1228 | { |
1229 | 1229 | if ($temp === false) { |
1230 | 1230 | $configFile = dirname(__FILE__).'/../CodeSniffer.conf'; |
@@ -160,16 +160,16 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | $this->tokensWithTabs = array( |
163 | - T_WHITESPACE => true, |
|
164 | - T_COMMENT => true, |
|
165 | - T_DOC_COMMENT => true, |
|
166 | - T_DOC_COMMENT_WHITESPACE => true, |
|
167 | - T_DOC_COMMENT_STRING => true, |
|
168 | - T_CONSTANT_ENCAPSED_STRING => true, |
|
169 | - T_DOUBLE_QUOTED_STRING => true, |
|
170 | - T_HEREDOC => true, |
|
171 | - T_NOWDOC => true, |
|
172 | - T_INLINE_HTML => true, |
|
163 | + T_WHITESPACE => true, |
|
164 | + T_COMMENT => true, |
|
165 | + T_DOC_COMMENT => true, |
|
166 | + T_DOC_COMMENT_WHITESPACE => true, |
|
167 | + T_DOC_COMMENT_STRING => true, |
|
168 | + T_CONSTANT_ENCAPSED_STRING => true, |
|
169 | + T_DOUBLE_QUOTED_STRING => true, |
|
170 | + T_HEREDOC => true, |
|
171 | + T_NOWDOC => true, |
|
172 | + T_INLINE_HTML => true, |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | $this->numTokens = count($this->tokens); |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | $todo = array( |
674 | 674 | $stackPtr, |
675 | 675 | $opener, |
676 | - ); |
|
676 | + ); |
|
677 | 677 | |
678 | 678 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
679 | 679 | $type = $this->tokens[$stackPtr]['type']; |
@@ -406,60 +406,60 @@ |
||
406 | 406 | */ |
407 | 407 | |
408 | 408 | switch ($this->tokens[$i]['code']) { |
409 | - case T_OPEN_SQUARE_BRACKET: |
|
410 | - $squareOpeners[] = $i; |
|
411 | - |
|
412 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
413 | - echo str_repeat("\t", count($squareOpeners)); |
|
414 | - echo str_repeat("\t", count($curlyOpeners)); |
|
415 | - echo "=> Found square bracket opener at $i".PHP_EOL; |
|
416 | - } |
|
417 | - break; |
|
418 | - case T_OPEN_CURLY_BRACKET: |
|
419 | - if (isset($this->tokens[$i]['scope_closer']) === false) { |
|
420 | - $curlyOpeners[] = $i; |
|
409 | + case T_OPEN_SQUARE_BRACKET: |
|
410 | + $squareOpeners[] = $i; |
|
421 | 411 | |
422 | 412 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
423 | 413 | echo str_repeat("\t", count($squareOpeners)); |
424 | 414 | echo str_repeat("\t", count($curlyOpeners)); |
425 | - echo "=> Found curly bracket opener at $i".PHP_EOL; |
|
415 | + echo "=> Found square bracket opener at $i".PHP_EOL; |
|
426 | 416 | } |
427 | - } |
|
428 | - break; |
|
429 | - case T_CLOSE_SQUARE_BRACKET: |
|
430 | - if (empty($squareOpeners) === false) { |
|
431 | - $opener = array_pop($squareOpeners); |
|
432 | - $this->tokens[$i]['bracket_opener'] = $opener; |
|
433 | - $this->tokens[$i]['bracket_closer'] = $i; |
|
434 | - $this->tokens[$opener]['bracket_opener'] = $opener; |
|
435 | - $this->tokens[$opener]['bracket_closer'] = $i; |
|
417 | + break; |
|
418 | + case T_OPEN_CURLY_BRACKET: |
|
419 | + if (isset($this->tokens[$i]['scope_closer']) === false) { |
|
420 | + $curlyOpeners[] = $i; |
|
436 | 421 | |
437 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
438 | - echo str_repeat("\t", count($squareOpeners)); |
|
439 | - echo str_repeat("\t", count($curlyOpeners)); |
|
440 | - echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL; |
|
422 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
423 | + echo str_repeat("\t", count($squareOpeners)); |
|
424 | + echo str_repeat("\t", count($curlyOpeners)); |
|
425 | + echo "=> Found curly bracket opener at $i".PHP_EOL; |
|
426 | + } |
|
441 | 427 | } |
442 | - } |
|
443 | - break; |
|
444 | - case T_CLOSE_CURLY_BRACKET: |
|
445 | - if (empty($curlyOpeners) === false |
|
446 | - && isset($this->tokens[$i]['scope_opener']) === false |
|
447 | - ) { |
|
448 | - $opener = array_pop($curlyOpeners); |
|
449 | - $this->tokens[$i]['bracket_opener'] = $opener; |
|
450 | - $this->tokens[$i]['bracket_closer'] = $i; |
|
451 | - $this->tokens[$opener]['bracket_opener'] = $opener; |
|
452 | - $this->tokens[$opener]['bracket_closer'] = $i; |
|
428 | + break; |
|
429 | + case T_CLOSE_SQUARE_BRACKET: |
|
430 | + if (empty($squareOpeners) === false) { |
|
431 | + $opener = array_pop($squareOpeners); |
|
432 | + $this->tokens[$i]['bracket_opener'] = $opener; |
|
433 | + $this->tokens[$i]['bracket_closer'] = $i; |
|
434 | + $this->tokens[$opener]['bracket_opener'] = $opener; |
|
435 | + $this->tokens[$opener]['bracket_closer'] = $i; |
|
453 | 436 | |
454 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | - echo str_repeat("\t", count($squareOpeners)); |
|
456 | - echo str_repeat("\t", count($curlyOpeners)); |
|
457 | - echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL; |
|
437 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
438 | + echo str_repeat("\t", count($squareOpeners)); |
|
439 | + echo str_repeat("\t", count($curlyOpeners)); |
|
440 | + echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL; |
|
441 | + } |
|
458 | 442 | } |
459 | - } |
|
460 | - break; |
|
461 | - default: |
|
462 | - continue; |
|
443 | + break; |
|
444 | + case T_CLOSE_CURLY_BRACKET: |
|
445 | + if (empty($curlyOpeners) === false |
|
446 | + && isset($this->tokens[$i]['scope_opener']) === false |
|
447 | + ) { |
|
448 | + $opener = array_pop($curlyOpeners); |
|
449 | + $this->tokens[$i]['bracket_opener'] = $opener; |
|
450 | + $this->tokens[$i]['bracket_closer'] = $i; |
|
451 | + $this->tokens[$opener]['bracket_opener'] = $opener; |
|
452 | + $this->tokens[$opener]['bracket_closer'] = $i; |
|
453 | + |
|
454 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | + echo str_repeat("\t", count($squareOpeners)); |
|
456 | + echo str_repeat("\t", count($curlyOpeners)); |
|
457 | + echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL; |
|
458 | + } |
|
459 | + } |
|
460 | + break; |
|
461 | + default: |
|
462 | + continue; |
|
463 | 463 | }//end switch |
464 | 464 | }//end for |
465 | 465 |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return void |
62 | 62 | * @throws TokenizerException If the file appears to be minified. |
63 | 63 | */ |
64 | - public function __construct($content, $config, $eolChar='\n') |
|
64 | + public function __construct($content, $config, $eolChar = '\n') |
|
65 | 65 | { |
66 | 66 | $this->eolChar = $eolChar; |
67 | 67 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return boolean |
94 | 94 | */ |
95 | - protected function isMinifiedContent($content, $eolChar='\n') |
|
95 | + protected function isMinifiedContent($content, $eolChar = '\n') |
|
96 | 96 | { |
97 | 97 | // Minified files often have a very large number of characters per line |
98 | 98 | // and cause issues when tokenizing. |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @return void |
265 | 265 | */ |
266 | - public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ') |
|
266 | + public function replaceTabsInToken(&$token, $prefix = ' ', $padding = ' ') |
|
267 | 267 | { |
268 | 268 | $checkEncoding = false; |
269 | 269 | if ($this->config->encoding !== 'iso-8859-1' && function_exists('iconv_strlen') === true) { |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | * |
565 | 565 | * @return int The position in the stack that closed the scope. |
566 | 566 | */ |
567 | - private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0) |
|
567 | + private function recurseScopeMap($stackPtr, $depth = 1, &$ignore = 0) |
|
568 | 568 | { |
569 | 569 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
570 | 570 | echo str_repeat("\t", $depth); |
@@ -57,6 +57,7 @@ |
||
57 | 57 | * @param string $content The content to tokenize, |
58 | 58 | * @param \Symplify\PHP7_CodeSniffer\Config | null $config The config data for the run. |
59 | 59 | * @param string $eolChar The EOL char used in the content. |
60 | + * @param \Symplify\PHP7_CodeSniffer\Config $config |
|
60 | 61 | * |
61 | 62 | * @return void |
62 | 63 | * @throws TokenizerException If the file appears to be minified. |
@@ -28,232 +28,232 @@ discard block |
||
28 | 28 | public $scopeOpeners = array( |
29 | 29 | T_IF => array( |
30 | 30 | 'start' => array( |
31 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
32 | - T_COLON => T_COLON, |
|
31 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
32 | + T_COLON => T_COLON, |
|
33 | 33 | ), |
34 | 34 | 'end' => array( |
35 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
36 | - T_ENDIF => T_ENDIF, |
|
37 | - T_ELSE => T_ELSE, |
|
38 | - T_ELSEIF => T_ELSEIF, |
|
35 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
36 | + T_ENDIF => T_ENDIF, |
|
37 | + T_ELSE => T_ELSE, |
|
38 | + T_ELSEIF => T_ELSEIF, |
|
39 | 39 | ), |
40 | 40 | 'strict' => false, |
41 | 41 | 'shared' => false, |
42 | 42 | 'with' => array( |
43 | - T_ELSE => T_ELSE, |
|
44 | - T_ELSEIF => T_ELSEIF, |
|
43 | + T_ELSE => T_ELSE, |
|
44 | + T_ELSEIF => T_ELSEIF, |
|
45 | 45 | ), |
46 | - ), |
|
46 | + ), |
|
47 | 47 | T_TRY => array( |
48 | 48 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
49 | 49 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
50 | 50 | 'strict' => true, |
51 | 51 | 'shared' => false, |
52 | 52 | 'with' => array(), |
53 | - ), |
|
53 | + ), |
|
54 | 54 | T_CATCH => array( |
55 | 55 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
56 | 56 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
57 | 57 | 'strict' => true, |
58 | 58 | 'shared' => false, |
59 | 59 | 'with' => array(), |
60 | - ), |
|
60 | + ), |
|
61 | 61 | T_FINALLY => array( |
62 | 62 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
63 | 63 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
64 | 64 | 'strict' => true, |
65 | 65 | 'shared' => false, |
66 | 66 | 'with' => array(), |
67 | - ), |
|
67 | + ), |
|
68 | 68 | T_ELSE => array( |
69 | 69 | 'start' => array( |
70 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
71 | - T_COLON => T_COLON, |
|
70 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
71 | + T_COLON => T_COLON, |
|
72 | 72 | ), |
73 | 73 | 'end' => array( |
74 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
75 | - T_ENDIF => T_ENDIF, |
|
74 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
75 | + T_ENDIF => T_ENDIF, |
|
76 | 76 | ), |
77 | 77 | 'strict' => false, |
78 | 78 | 'shared' => false, |
79 | 79 | 'with' => array( |
80 | - T_IF => T_IF, |
|
81 | - T_ELSEIF => T_ELSEIF, |
|
80 | + T_IF => T_IF, |
|
81 | + T_ELSEIF => T_ELSEIF, |
|
82 | 82 | ), |
83 | - ), |
|
83 | + ), |
|
84 | 84 | T_ELSEIF => array( |
85 | 85 | 'start' => array( |
86 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
87 | - T_COLON => T_COLON, |
|
86 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
87 | + T_COLON => T_COLON, |
|
88 | 88 | ), |
89 | 89 | 'end' => array( |
90 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
91 | - T_ENDIF => T_ENDIF, |
|
92 | - T_ELSE => T_ELSE, |
|
93 | - T_ELSEIF => T_ELSEIF, |
|
90 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
91 | + T_ENDIF => T_ENDIF, |
|
92 | + T_ELSE => T_ELSE, |
|
93 | + T_ELSEIF => T_ELSEIF, |
|
94 | 94 | ), |
95 | 95 | 'strict' => false, |
96 | 96 | 'shared' => false, |
97 | 97 | 'with' => array( |
98 | - T_IF => T_IF, |
|
99 | - T_ELSE => T_ELSE, |
|
98 | + T_IF => T_IF, |
|
99 | + T_ELSE => T_ELSE, |
|
100 | 100 | ), |
101 | - ), |
|
101 | + ), |
|
102 | 102 | T_FOR => array( |
103 | 103 | 'start' => array( |
104 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
105 | - T_COLON => T_COLON, |
|
104 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
105 | + T_COLON => T_COLON, |
|
106 | 106 | ), |
107 | 107 | 'end' => array( |
108 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
109 | - T_ENDFOR => T_ENDFOR, |
|
108 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
109 | + T_ENDFOR => T_ENDFOR, |
|
110 | 110 | ), |
111 | 111 | 'strict' => false, |
112 | 112 | 'shared' => false, |
113 | 113 | 'with' => array(), |
114 | - ), |
|
114 | + ), |
|
115 | 115 | T_FOREACH => array( |
116 | 116 | 'start' => array( |
117 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
118 | - T_COLON => T_COLON, |
|
117 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
118 | + T_COLON => T_COLON, |
|
119 | 119 | ), |
120 | 120 | 'end' => array( |
121 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
122 | - T_ENDFOREACH => T_ENDFOREACH, |
|
121 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
122 | + T_ENDFOREACH => T_ENDFOREACH, |
|
123 | 123 | ), |
124 | 124 | 'strict' => false, |
125 | 125 | 'shared' => false, |
126 | 126 | 'with' => array(), |
127 | - ), |
|
127 | + ), |
|
128 | 128 | T_INTERFACE => array( |
129 | 129 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
130 | 130 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
131 | 131 | 'strict' => true, |
132 | 132 | 'shared' => false, |
133 | 133 | 'with' => array(), |
134 | - ), |
|
134 | + ), |
|
135 | 135 | T_FUNCTION => array( |
136 | 136 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
137 | 137 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
138 | 138 | 'strict' => true, |
139 | 139 | 'shared' => false, |
140 | 140 | 'with' => array(), |
141 | - ), |
|
141 | + ), |
|
142 | 142 | T_CLASS => array( |
143 | 143 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
144 | 144 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
145 | 145 | 'strict' => true, |
146 | 146 | 'shared' => false, |
147 | 147 | 'with' => array(), |
148 | - ), |
|
148 | + ), |
|
149 | 149 | T_TRAIT => array( |
150 | 150 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
151 | 151 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
152 | 152 | 'strict' => true, |
153 | 153 | 'shared' => false, |
154 | 154 | 'with' => array(), |
155 | - ), |
|
155 | + ), |
|
156 | 156 | T_USE => array( |
157 | 157 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
158 | 158 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
159 | 159 | 'strict' => false, |
160 | 160 | 'shared' => false, |
161 | 161 | 'with' => array(), |
162 | - ), |
|
162 | + ), |
|
163 | 163 | T_DECLARE => array( |
164 | 164 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
165 | 165 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
166 | 166 | 'strict' => false, |
167 | 167 | 'shared' => false, |
168 | 168 | 'with' => array(), |
169 | - ), |
|
169 | + ), |
|
170 | 170 | T_NAMESPACE => array( |
171 | 171 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
172 | 172 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
173 | 173 | 'strict' => false, |
174 | 174 | 'shared' => false, |
175 | 175 | 'with' => array(), |
176 | - ), |
|
176 | + ), |
|
177 | 177 | T_WHILE => array( |
178 | 178 | 'start' => array( |
179 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
180 | - T_COLON => T_COLON, |
|
179 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
180 | + T_COLON => T_COLON, |
|
181 | 181 | ), |
182 | 182 | 'end' => array( |
183 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
184 | - T_ENDWHILE => T_ENDWHILE, |
|
183 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
184 | + T_ENDWHILE => T_ENDWHILE, |
|
185 | 185 | ), |
186 | 186 | 'strict' => false, |
187 | 187 | 'shared' => false, |
188 | 188 | 'with' => array(), |
189 | - ), |
|
189 | + ), |
|
190 | 190 | T_DO => array( |
191 | 191 | 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
192 | 192 | 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
193 | 193 | 'strict' => true, |
194 | 194 | 'shared' => false, |
195 | 195 | 'with' => array(), |
196 | - ), |
|
196 | + ), |
|
197 | 197 | T_SWITCH => array( |
198 | 198 | 'start' => array( |
199 | - T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
200 | - T_COLON => T_COLON, |
|
199 | + T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, |
|
200 | + T_COLON => T_COLON, |
|
201 | 201 | ), |
202 | 202 | 'end' => array( |
203 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
204 | - T_ENDSWITCH => T_ENDSWITCH, |
|
203 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
204 | + T_ENDSWITCH => T_ENDSWITCH, |
|
205 | 205 | ), |
206 | 206 | 'strict' => true, |
207 | 207 | 'shared' => false, |
208 | 208 | 'with' => array(), |
209 | - ), |
|
209 | + ), |
|
210 | 210 | T_CASE => array( |
211 | 211 | 'start' => array( |
212 | - T_COLON => T_COLON, |
|
213 | - T_SEMICOLON => T_SEMICOLON, |
|
212 | + T_COLON => T_COLON, |
|
213 | + T_SEMICOLON => T_SEMICOLON, |
|
214 | 214 | ), |
215 | 215 | 'end' => array( |
216 | - T_BREAK => T_BREAK, |
|
217 | - T_RETURN => T_RETURN, |
|
218 | - T_CONTINUE => T_CONTINUE, |
|
219 | - T_THROW => T_THROW, |
|
220 | - T_EXIT => T_EXIT, |
|
216 | + T_BREAK => T_BREAK, |
|
217 | + T_RETURN => T_RETURN, |
|
218 | + T_CONTINUE => T_CONTINUE, |
|
219 | + T_THROW => T_THROW, |
|
220 | + T_EXIT => T_EXIT, |
|
221 | 221 | ), |
222 | 222 | 'strict' => true, |
223 | 223 | 'shared' => true, |
224 | 224 | 'with' => array( |
225 | - T_DEFAULT => T_DEFAULT, |
|
226 | - T_CASE => T_CASE, |
|
227 | - T_SWITCH => T_SWITCH, |
|
225 | + T_DEFAULT => T_DEFAULT, |
|
226 | + T_CASE => T_CASE, |
|
227 | + T_SWITCH => T_SWITCH, |
|
228 | 228 | ), |
229 | - ), |
|
229 | + ), |
|
230 | 230 | T_DEFAULT => array( |
231 | 231 | 'start' => array( |
232 | - T_COLON => T_COLON, |
|
233 | - T_SEMICOLON => T_SEMICOLON, |
|
232 | + T_COLON => T_COLON, |
|
233 | + T_SEMICOLON => T_SEMICOLON, |
|
234 | 234 | ), |
235 | 235 | 'end' => array( |
236 | - T_BREAK => T_BREAK, |
|
237 | - T_RETURN => T_RETURN, |
|
238 | - T_CONTINUE => T_CONTINUE, |
|
239 | - T_THROW => T_THROW, |
|
240 | - T_EXIT => T_EXIT, |
|
236 | + T_BREAK => T_BREAK, |
|
237 | + T_RETURN => T_RETURN, |
|
238 | + T_CONTINUE => T_CONTINUE, |
|
239 | + T_THROW => T_THROW, |
|
240 | + T_EXIT => T_EXIT, |
|
241 | 241 | ), |
242 | 242 | 'strict' => true, |
243 | 243 | 'shared' => true, |
244 | 244 | 'with' => array( |
245 | - T_CASE => T_CASE, |
|
246 | - T_SWITCH => T_SWITCH, |
|
245 | + T_CASE => T_CASE, |
|
246 | + T_SWITCH => T_SWITCH, |
|
247 | 247 | ), |
248 | - ), |
|
248 | + ), |
|
249 | 249 | T_START_HEREDOC => array( |
250 | 250 | 'start' => array(T_START_HEREDOC => T_START_HEREDOC), |
251 | 251 | 'end' => array(T_END_HEREDOC => T_END_HEREDOC), |
252 | 252 | 'strict' => true, |
253 | 253 | 'shared' => false, |
254 | 254 | 'with' => array(), |
255 | - ), |
|
256 | - ); |
|
255 | + ), |
|
256 | + ); |
|
257 | 257 | |
258 | 258 | /** |
259 | 259 | * A list of tokens that end the scope. |
@@ -265,15 +265,15 @@ discard block |
||
265 | 265 | * @var array |
266 | 266 | */ |
267 | 267 | public $endScopeTokens = array( |
268 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
269 | - T_ENDIF => T_ENDIF, |
|
270 | - T_ENDFOR => T_ENDFOR, |
|
271 | - T_ENDFOREACH => T_ENDFOREACH, |
|
272 | - T_ENDWHILE => T_ENDWHILE, |
|
273 | - T_ENDSWITCH => T_ENDSWITCH, |
|
274 | - T_BREAK => T_BREAK, |
|
275 | - T_END_HEREDOC => T_END_HEREDOC, |
|
276 | - ); |
|
268 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
269 | + T_ENDIF => T_ENDIF, |
|
270 | + T_ENDFOR => T_ENDFOR, |
|
271 | + T_ENDFOREACH => T_ENDFOREACH, |
|
272 | + T_ENDWHILE => T_ENDWHILE, |
|
273 | + T_ENDSWITCH => T_ENDSWITCH, |
|
274 | + T_BREAK => T_BREAK, |
|
275 | + T_END_HEREDOC => T_END_HEREDOC, |
|
276 | + ); |
|
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Known lengths of tokens. |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | T_BACKTICK => 1, |
424 | 424 | T_OPEN_SHORT_ARRAY => 1, |
425 | 425 | T_CLOSE_SHORT_ARRAY => 1, |
426 | - ); |
|
426 | + ); |
|
427 | 427 | |
428 | 428 | |
429 | 429 | /** |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | // Binary casts need a special token. |
556 | 556 | if ($token[0] === 'b"') { |
557 | 557 | $finalTokens[$newStackPtr] = array( |
558 | - 'code' => T_BINARY_CAST, |
|
559 | - 'type' => 'T_BINARY_CAST', |
|
560 | - 'content' => 'b', |
|
561 | - ); |
|
558 | + 'code' => T_BINARY_CAST, |
|
559 | + 'type' => 'T_BINARY_CAST', |
|
560 | + 'content' => 'b', |
|
561 | + ); |
|
562 | 562 | $newStackPtr++; |
563 | 563 | } |
564 | 564 | |
@@ -842,10 +842,10 @@ discard block |
||
842 | 842 | && $tokens[($stackPtr - 1)][0] !== T_OBJECT_OPERATOR |
843 | 843 | ) { |
844 | 844 | $finalTokens[$newStackPtr] = array( |
845 | - 'content' => $token[1], |
|
846 | - 'code' => T_TRAIT, |
|
847 | - 'type' => 'T_TRAIT', |
|
848 | - ); |
|
845 | + 'content' => $token[1], |
|
846 | + 'code' => T_TRAIT, |
|
847 | + 'type' => 'T_TRAIT', |
|
848 | + ); |
|
849 | 849 | |
850 | 850 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
851 | 851 | echo "\t\t* token $stackPtr changed from T_STRING to T_TRAIT".PHP_EOL; |
@@ -870,11 +870,11 @@ discard block |
||
870 | 870 | && $tokens[($stackPtr - 1)][0] !== T_PAAMAYIM_NEKUDOTAYIM |
871 | 871 | ) { |
872 | 872 | $stopTokens = array( |
873 | - T_CASE => true, |
|
874 | - T_SEMICOLON => true, |
|
875 | - T_OPEN_CURLY_BRACKET => true, |
|
876 | - T_INLINE_THEN => true, |
|
877 | - ); |
|
873 | + T_CASE => true, |
|
874 | + T_SEMICOLON => true, |
|
875 | + T_OPEN_CURLY_BRACKET => true, |
|
876 | + T_INLINE_THEN => true, |
|
877 | + ); |
|
878 | 878 | |
879 | 879 | for ($x = ($newStackPtr - 1); $x > 0; $x--) { |
880 | 880 | if (isset($stopTokens[$finalTokens[$x]['code']]) === true) { |
@@ -886,10 +886,10 @@ discard block |
||
886 | 886 | && $finalTokens[$x]['code'] !== T_INLINE_THEN |
887 | 887 | ) { |
888 | 888 | $finalTokens[$newStackPtr] = array( |
889 | - 'content' => $token[1].':', |
|
890 | - 'code' => T_GOTO_LABEL, |
|
891 | - 'type' => 'T_GOTO_LABEL', |
|
892 | - ); |
|
889 | + 'content' => $token[1].':', |
|
890 | + 'code' => T_GOTO_LABEL, |
|
891 | + 'type' => 'T_GOTO_LABEL', |
|
892 | + ); |
|
893 | 893 | |
894 | 894 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
895 | 895 | echo "\t\t* token $stackPtr changed from T_STRING to T_GOTO_LABEL".PHP_EOL; |
@@ -913,24 +913,24 @@ discard block |
||
913 | 913 | && strtolower($token[1]) !== 'elseif' |
914 | 914 | ) { |
915 | 915 | $finalTokens[$newStackPtr] = array( |
916 | - 'content' => substr($token[1], 0, 4), |
|
917 | - 'code' => T_ELSE, |
|
918 | - 'type' => 'T_ELSE', |
|
919 | - ); |
|
916 | + 'content' => substr($token[1], 0, 4), |
|
917 | + 'code' => T_ELSE, |
|
918 | + 'type' => 'T_ELSE', |
|
919 | + ); |
|
920 | 920 | |
921 | 921 | $newStackPtr++; |
922 | 922 | $finalTokens[$newStackPtr] = array( |
923 | - 'content' => substr($token[1], 4, -2), |
|
924 | - 'code' => T_WHITESPACE, |
|
925 | - 'type' => 'T_WHITESPACE', |
|
926 | - ); |
|
923 | + 'content' => substr($token[1], 4, -2), |
|
924 | + 'code' => T_WHITESPACE, |
|
925 | + 'type' => 'T_WHITESPACE', |
|
926 | + ); |
|
927 | 927 | |
928 | 928 | $newStackPtr++; |
929 | 929 | $finalTokens[$newStackPtr] = array( |
930 | - 'content' => substr($token[1], -2), |
|
931 | - 'code' => T_IF, |
|
932 | - 'type' => 'T_IF', |
|
933 | - ); |
|
930 | + 'content' => substr($token[1], -2), |
|
931 | + 'code' => T_IF, |
|
932 | + 'type' => 'T_IF', |
|
933 | + ); |
|
934 | 934 | |
935 | 935 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
936 | 936 | echo "\t\t* token $stackPtr changed from T_ELSEIF to T_ELSE/T_WHITESPACE/T_IF".PHP_EOL; |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | |
948 | 948 | if ($tokenIsArray === true && token_name($token[0]) === 'T_HASHBANG') { |
949 | 949 | $finalTokens[$newStackPtr] = array( |
950 | - 'content' => $token[1], |
|
951 | - 'code' => T_INLINE_HTML, |
|
952 | - 'type' => 'T_INLINE_HTML', |
|
953 | - ); |
|
950 | + 'content' => $token[1], |
|
951 | + 'code' => T_INLINE_HTML, |
|
952 | + 'type' => 'T_INLINE_HTML', |
|
953 | + ); |
|
954 | 954 | |
955 | 955 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
956 | 956 | echo "\t\t* token $stackPtr changed from T_HASHBANG to T_INLINE_HTML".PHP_EOL; |
@@ -971,10 +971,10 @@ discard block |
||
971 | 971 | $tokenLines = explode($this->eolChar, $token[1]); |
972 | 972 | $numLines = count($tokenLines); |
973 | 973 | $newToken = array( |
974 | - 'type' => token_name($token[0]), |
|
975 | - 'code' => $token[0], |
|
976 | - 'content' => '', |
|
977 | - ); |
|
974 | + 'type' => token_name($token[0]), |
|
975 | + 'code' => $token[0], |
|
976 | + 'content' => '', |
|
977 | + ); |
|
978 | 978 | |
979 | 979 | for ($i = 0; $i < $numLines; $i++) { |
980 | 980 | $newToken['content'] = $tokenLines[$i]; |
@@ -1005,13 +1005,13 @@ discard block |
||
1005 | 1005 | T_USE => true, |
1006 | 1006 | T_NAMESPACE => true, |
1007 | 1007 | T_PAAMAYIM_NEKUDOTAYIM => true, |
1008 | - ); |
|
1008 | + ); |
|
1009 | 1009 | if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]) === true) { |
1010 | 1010 | $finalTokens[$newStackPtr] = array( |
1011 | - 'content' => $token[1], |
|
1012 | - 'code' => T_STRING, |
|
1013 | - 'type' => 'T_STRING', |
|
1014 | - ); |
|
1011 | + 'content' => $token[1], |
|
1012 | + 'code' => T_STRING, |
|
1013 | + 'type' => 'T_STRING', |
|
1014 | + ); |
|
1015 | 1015 | $newStackPtr++; |
1016 | 1016 | continue; |
1017 | 1017 | } |
@@ -1309,7 +1309,7 @@ discard block |
||
1309 | 1309 | T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS, |
1310 | 1310 | T_VARIABLE => T_VARIABLE, |
1311 | 1311 | T_STRING => T_STRING, |
1312 | - ); |
|
1312 | + ); |
|
1313 | 1313 | |
1314 | 1314 | if (isset($allowed[$this->tokens[$x]['code']]) === false |
1315 | 1315 | && isset($this->tokens[$i]['bracket_closer']) === true |
@@ -1371,7 +1371,7 @@ discard block |
||
1371 | 1371 | T_OBJECT_OPERATOR => true, |
1372 | 1372 | T_NS_SEPARATOR => true, |
1373 | 1373 | T_PAAMAYIM_NEKUDOTAYIM => true, |
1374 | - ); |
|
1374 | + ); |
|
1375 | 1375 | if (isset($context[$this->tokens[$x]['code']]) === true) { |
1376 | 1376 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
1377 | 1377 | $line = $this->tokens[$i]['line']; |
@@ -1604,13 +1604,13 @@ discard block |
||
1604 | 1604 | self::$_resolveTokenCache[$cacheKey] = $newToken; |
1605 | 1605 | } else if ($token[0] === T_CURLY_OPEN) { |
1606 | 1606 | $newToken = array( |
1607 | - 'code' => T_OPEN_CURLY_BRACKET, |
|
1608 | - 'type' => 'T_OPEN_CURLY_BRACKET', |
|
1607 | + 'code' => T_OPEN_CURLY_BRACKET, |
|
1608 | + 'type' => 'T_OPEN_CURLY_BRACKET', |
|
1609 | 1609 | ); |
1610 | 1610 | } else { |
1611 | 1611 | $newToken = array( |
1612 | - 'code' => $token[0], |
|
1613 | - 'type' => token_name($token[0]), |
|
1612 | + 'code' => $token[0], |
|
1613 | + 'type' => token_name($token[0]), |
|
1614 | 1614 | ); |
1615 | 1615 | |
1616 | 1616 | self::$_resolveTokenCache[$token[0]] = $newToken; |
@@ -1450,24 +1450,24 @@ discard block |
||
1450 | 1450 | |
1451 | 1451 | if ($token[0] === T_STRING) { |
1452 | 1452 | switch ($cacheKey) { |
1453 | - case 'false': |
|
1454 | - $newToken['type'] = 'T_FALSE'; |
|
1455 | - break; |
|
1456 | - case 'true': |
|
1457 | - $newToken['type'] = 'T_TRUE'; |
|
1458 | - break; |
|
1459 | - case 'null': |
|
1460 | - $newToken['type'] = 'T_NULL'; |
|
1461 | - break; |
|
1462 | - case 'self': |
|
1463 | - $newToken['type'] = 'T_SELF'; |
|
1464 | - break; |
|
1465 | - case 'parent': |
|
1466 | - $newToken['type'] = 'T_PARENT'; |
|
1467 | - break; |
|
1468 | - default: |
|
1469 | - $newToken['type'] = 'T_STRING'; |
|
1470 | - break; |
|
1453 | + case 'false': |
|
1454 | + $newToken['type'] = 'T_FALSE'; |
|
1455 | + break; |
|
1456 | + case 'true': |
|
1457 | + $newToken['type'] = 'T_TRUE'; |
|
1458 | + break; |
|
1459 | + case 'null': |
|
1460 | + $newToken['type'] = 'T_NULL'; |
|
1461 | + break; |
|
1462 | + case 'self': |
|
1463 | + $newToken['type'] = 'T_SELF'; |
|
1464 | + break; |
|
1465 | + case 'parent': |
|
1466 | + $newToken['type'] = 'T_PARENT'; |
|
1467 | + break; |
|
1468 | + default: |
|
1469 | + $newToken['type'] = 'T_STRING'; |
|
1470 | + break; |
|
1471 | 1471 | } |
1472 | 1472 | |
1473 | 1473 | $newToken['code'] = constant($newToken['type']); |
@@ -1509,87 +1509,87 @@ discard block |
||
1509 | 1509 | $newToken = array(); |
1510 | 1510 | |
1511 | 1511 | switch ($token) { |
1512 | - case '{': |
|
1513 | - $newToken['type'] = 'T_OPEN_CURLY_BRACKET'; |
|
1514 | - break; |
|
1515 | - case '}': |
|
1516 | - $newToken['type'] = 'T_CLOSE_CURLY_BRACKET'; |
|
1517 | - break; |
|
1518 | - case '[': |
|
1519 | - $newToken['type'] = 'T_OPEN_SQUARE_BRACKET'; |
|
1520 | - break; |
|
1521 | - case ']': |
|
1522 | - $newToken['type'] = 'T_CLOSE_SQUARE_BRACKET'; |
|
1523 | - break; |
|
1524 | - case '(': |
|
1525 | - $newToken['type'] = 'T_OPEN_PARENTHESIS'; |
|
1526 | - break; |
|
1527 | - case ')': |
|
1528 | - $newToken['type'] = 'T_CLOSE_PARENTHESIS'; |
|
1529 | - break; |
|
1530 | - case ':': |
|
1531 | - $newToken['type'] = 'T_COLON'; |
|
1532 | - break; |
|
1533 | - case '.': |
|
1534 | - $newToken['type'] = 'T_STRING_CONCAT'; |
|
1535 | - break; |
|
1536 | - case '?': |
|
1537 | - $newToken['type'] = 'T_INLINE_THEN'; |
|
1538 | - break; |
|
1539 | - case ';': |
|
1540 | - $newToken['type'] = 'T_SEMICOLON'; |
|
1541 | - break; |
|
1542 | - case '=': |
|
1543 | - $newToken['type'] = 'T_EQUAL'; |
|
1544 | - break; |
|
1545 | - case '*': |
|
1546 | - $newToken['type'] = 'T_MULTIPLY'; |
|
1547 | - break; |
|
1548 | - case '/': |
|
1549 | - $newToken['type'] = 'T_DIVIDE'; |
|
1550 | - break; |
|
1551 | - case '+': |
|
1552 | - $newToken['type'] = 'T_PLUS'; |
|
1553 | - break; |
|
1554 | - case '-': |
|
1555 | - $newToken['type'] = 'T_MINUS'; |
|
1556 | - break; |
|
1557 | - case '%': |
|
1558 | - $newToken['type'] = 'T_MODULUS'; |
|
1559 | - break; |
|
1560 | - case '^': |
|
1561 | - $newToken['type'] = 'T_BITWISE_XOR'; |
|
1562 | - break; |
|
1563 | - case '&': |
|
1564 | - $newToken['type'] = 'T_BITWISE_AND'; |
|
1565 | - break; |
|
1566 | - case '|': |
|
1567 | - $newToken['type'] = 'T_BITWISE_OR'; |
|
1568 | - break; |
|
1569 | - case '<': |
|
1570 | - $newToken['type'] = 'T_LESS_THAN'; |
|
1571 | - break; |
|
1572 | - case '>': |
|
1573 | - $newToken['type'] = 'T_GREATER_THAN'; |
|
1574 | - break; |
|
1575 | - case '!': |
|
1576 | - $newToken['type'] = 'T_BOOLEAN_NOT'; |
|
1577 | - break; |
|
1578 | - case ',': |
|
1579 | - $newToken['type'] = 'T_COMMA'; |
|
1580 | - break; |
|
1581 | - case '@': |
|
1582 | - $newToken['type'] = 'T_ASPERAND'; |
|
1583 | - break; |
|
1584 | - case '$': |
|
1585 | - $newToken['type'] = 'T_DOLLAR'; |
|
1586 | - break; |
|
1587 | - case '`': |
|
1588 | - $newToken['type'] = 'T_BACKTICK'; |
|
1589 | - break; |
|
1590 | - default: |
|
1591 | - $newToken['type'] = 'T_NONE'; |
|
1592 | - break; |
|
1512 | + case '{': |
|
1513 | + $newToken['type'] = 'T_OPEN_CURLY_BRACKET'; |
|
1514 | + break; |
|
1515 | + case '}': |
|
1516 | + $newToken['type'] = 'T_CLOSE_CURLY_BRACKET'; |
|
1517 | + break; |
|
1518 | + case '[': |
|
1519 | + $newToken['type'] = 'T_OPEN_SQUARE_BRACKET'; |
|
1520 | + break; |
|
1521 | + case ']': |
|
1522 | + $newToken['type'] = 'T_CLOSE_SQUARE_BRACKET'; |
|
1523 | + break; |
|
1524 | + case '(': |
|
1525 | + $newToken['type'] = 'T_OPEN_PARENTHESIS'; |
|
1526 | + break; |
|
1527 | + case ')': |
|
1528 | + $newToken['type'] = 'T_CLOSE_PARENTHESIS'; |
|
1529 | + break; |
|
1530 | + case ':': |
|
1531 | + $newToken['type'] = 'T_COLON'; |
|
1532 | + break; |
|
1533 | + case '.': |
|
1534 | + $newToken['type'] = 'T_STRING_CONCAT'; |
|
1535 | + break; |
|
1536 | + case '?': |
|
1537 | + $newToken['type'] = 'T_INLINE_THEN'; |
|
1538 | + break; |
|
1539 | + case ';': |
|
1540 | + $newToken['type'] = 'T_SEMICOLON'; |
|
1541 | + break; |
|
1542 | + case '=': |
|
1543 | + $newToken['type'] = 'T_EQUAL'; |
|
1544 | + break; |
|
1545 | + case '*': |
|
1546 | + $newToken['type'] = 'T_MULTIPLY'; |
|
1547 | + break; |
|
1548 | + case '/': |
|
1549 | + $newToken['type'] = 'T_DIVIDE'; |
|
1550 | + break; |
|
1551 | + case '+': |
|
1552 | + $newToken['type'] = 'T_PLUS'; |
|
1553 | + break; |
|
1554 | + case '-': |
|
1555 | + $newToken['type'] = 'T_MINUS'; |
|
1556 | + break; |
|
1557 | + case '%': |
|
1558 | + $newToken['type'] = 'T_MODULUS'; |
|
1559 | + break; |
|
1560 | + case '^': |
|
1561 | + $newToken['type'] = 'T_BITWISE_XOR'; |
|
1562 | + break; |
|
1563 | + case '&': |
|
1564 | + $newToken['type'] = 'T_BITWISE_AND'; |
|
1565 | + break; |
|
1566 | + case '|': |
|
1567 | + $newToken['type'] = 'T_BITWISE_OR'; |
|
1568 | + break; |
|
1569 | + case '<': |
|
1570 | + $newToken['type'] = 'T_LESS_THAN'; |
|
1571 | + break; |
|
1572 | + case '>': |
|
1573 | + $newToken['type'] = 'T_GREATER_THAN'; |
|
1574 | + break; |
|
1575 | + case '!': |
|
1576 | + $newToken['type'] = 'T_BOOLEAN_NOT'; |
|
1577 | + break; |
|
1578 | + case ',': |
|
1579 | + $newToken['type'] = 'T_COMMA'; |
|
1580 | + break; |
|
1581 | + case '@': |
|
1582 | + $newToken['type'] = 'T_ASPERAND'; |
|
1583 | + break; |
|
1584 | + case '$': |
|
1585 | + $newToken['type'] = 'T_DOLLAR'; |
|
1586 | + break; |
|
1587 | + case '`': |
|
1588 | + $newToken['type'] = 'T_BACKTICK'; |
|
1589 | + break; |
|
1590 | + default: |
|
1591 | + $newToken['type'] = 'T_NONE'; |
|
1592 | + break; |
|
1593 | 1593 | }//end switch |
1594 | 1594 | |
1595 | 1595 | $newToken['code'] = constant($newToken['type']); |
@@ -29,100 +29,100 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public $scopeOpeners = array( |
31 | 31 | T_IF => array( |
32 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
33 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
34 | - 'strict' => false, |
|
35 | - 'shared' => false, |
|
36 | - 'with' => array(), |
|
37 | - ), |
|
32 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
33 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
34 | + 'strict' => false, |
|
35 | + 'shared' => false, |
|
36 | + 'with' => array(), |
|
37 | + ), |
|
38 | 38 | T_TRY => array( |
39 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
40 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
41 | - 'strict' => true, |
|
42 | - 'shared' => false, |
|
43 | - 'with' => array(), |
|
44 | - ), |
|
39 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
40 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
41 | + 'strict' => true, |
|
42 | + 'shared' => false, |
|
43 | + 'with' => array(), |
|
44 | + ), |
|
45 | 45 | T_CATCH => array( |
46 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
47 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
48 | - 'strict' => true, |
|
49 | - 'shared' => false, |
|
50 | - 'with' => array(), |
|
51 | - ), |
|
46 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
47 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
48 | + 'strict' => true, |
|
49 | + 'shared' => false, |
|
50 | + 'with' => array(), |
|
51 | + ), |
|
52 | 52 | T_ELSE => array( |
53 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
54 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
55 | - 'strict' => false, |
|
56 | - 'shared' => false, |
|
57 | - 'with' => array(), |
|
58 | - ), |
|
53 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
54 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
55 | + 'strict' => false, |
|
56 | + 'shared' => false, |
|
57 | + 'with' => array(), |
|
58 | + ), |
|
59 | 59 | T_FOR => array( |
60 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
61 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
62 | - 'strict' => false, |
|
63 | - 'shared' => false, |
|
64 | - 'with' => array(), |
|
65 | - ), |
|
60 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
61 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
62 | + 'strict' => false, |
|
63 | + 'shared' => false, |
|
64 | + 'with' => array(), |
|
65 | + ), |
|
66 | 66 | T_FUNCTION => array( |
67 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
68 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
69 | - 'strict' => false, |
|
70 | - 'shared' => false, |
|
71 | - 'with' => array(), |
|
72 | - ), |
|
67 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
68 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
69 | + 'strict' => false, |
|
70 | + 'shared' => false, |
|
71 | + 'with' => array(), |
|
72 | + ), |
|
73 | 73 | T_WHILE => array( |
74 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
75 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
76 | - 'strict' => false, |
|
77 | - 'shared' => false, |
|
78 | - 'with' => array(), |
|
79 | - ), |
|
74 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
75 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
76 | + 'strict' => false, |
|
77 | + 'shared' => false, |
|
78 | + 'with' => array(), |
|
79 | + ), |
|
80 | 80 | T_DO => array( |
81 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
82 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
83 | - 'strict' => true, |
|
84 | - 'shared' => false, |
|
85 | - 'with' => array(), |
|
86 | - ), |
|
81 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
82 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
83 | + 'strict' => true, |
|
84 | + 'shared' => false, |
|
85 | + 'with' => array(), |
|
86 | + ), |
|
87 | 87 | T_SWITCH => array( |
88 | - 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
89 | - 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
90 | - 'strict' => true, |
|
91 | - 'shared' => false, |
|
92 | - 'with' => array(), |
|
93 | - ), |
|
88 | + 'start' => array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET), |
|
89 | + 'end' => array(T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET), |
|
90 | + 'strict' => true, |
|
91 | + 'shared' => false, |
|
92 | + 'with' => array(), |
|
93 | + ), |
|
94 | 94 | T_CASE => array( |
95 | - 'start' => array(T_COLON => T_COLON), |
|
96 | - 'end' => array( |
|
95 | + 'start' => array(T_COLON => T_COLON), |
|
96 | + 'end' => array( |
|
97 | 97 | T_BREAK => T_BREAK, |
98 | 98 | T_RETURN => T_RETURN, |
99 | 99 | T_CONTINUE => T_CONTINUE, |
100 | 100 | T_THROW => T_THROW, |
101 | - ), |
|
102 | - 'strict' => true, |
|
103 | - 'shared' => true, |
|
104 | - 'with' => array( |
|
101 | + ), |
|
102 | + 'strict' => true, |
|
103 | + 'shared' => true, |
|
104 | + 'with' => array( |
|
105 | 105 | T_DEFAULT => T_DEFAULT, |
106 | 106 | T_CASE => T_CASE, |
107 | 107 | T_SWITCH => T_SWITCH, |
108 | - ), |
|
109 | - ), |
|
108 | + ), |
|
109 | + ), |
|
110 | 110 | T_DEFAULT => array( |
111 | - 'start' => array(T_COLON => T_COLON), |
|
112 | - 'end' => array( |
|
111 | + 'start' => array(T_COLON => T_COLON), |
|
112 | + 'end' => array( |
|
113 | 113 | T_BREAK => T_BREAK, |
114 | 114 | T_RETURN => T_RETURN, |
115 | 115 | T_CONTINUE => T_CONTINUE, |
116 | 116 | T_THROW => T_THROW, |
117 | - ), |
|
118 | - 'strict' => true, |
|
119 | - 'shared' => true, |
|
120 | - 'with' => array( |
|
117 | + ), |
|
118 | + 'strict' => true, |
|
119 | + 'shared' => true, |
|
120 | + 'with' => array( |
|
121 | 121 | T_CASE => T_CASE, |
122 | 122 | T_SWITCH => T_SWITCH, |
123 | - ), |
|
124 | - ), |
|
125 | - ); |
|
123 | + ), |
|
124 | + ), |
|
125 | + ); |
|
126 | 126 | |
127 | 127 | /** |
128 | 128 | * A list of tokens that end the scope. |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @var array |
135 | 135 | */ |
136 | 136 | public $endScopeTokens = array( |
137 | - T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
138 | - T_BREAK => T_BREAK, |
|
139 | - ); |
|
137 | + T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
|
138 | + T_BREAK => T_BREAK, |
|
139 | + ); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * A list of special JS tokens and their types. |
@@ -144,71 +144,71 @@ discard block |
||
144 | 144 | * @var array |
145 | 145 | */ |
146 | 146 | protected $tokenValues = array( |
147 | - 'function' => 'T_FUNCTION', |
|
148 | - 'prototype' => 'T_PROTOTYPE', |
|
149 | - 'try' => 'T_TRY', |
|
150 | - 'catch' => 'T_CATCH', |
|
151 | - 'return' => 'T_RETURN', |
|
152 | - 'throw' => 'T_THROW', |
|
153 | - 'break' => 'T_BREAK', |
|
154 | - 'switch' => 'T_SWITCH', |
|
155 | - 'continue' => 'T_CONTINUE', |
|
156 | - 'if' => 'T_IF', |
|
157 | - 'else' => 'T_ELSE', |
|
158 | - 'do' => 'T_DO', |
|
159 | - 'while' => 'T_WHILE', |
|
160 | - 'for' => 'T_FOR', |
|
161 | - 'var' => 'T_VAR', |
|
162 | - 'case' => 'T_CASE', |
|
163 | - 'default' => 'T_DEFAULT', |
|
164 | - 'true' => 'T_TRUE', |
|
165 | - 'false' => 'T_FALSE', |
|
166 | - 'null' => 'T_NULL', |
|
167 | - 'this' => 'T_THIS', |
|
168 | - 'typeof' => 'T_TYPEOF', |
|
169 | - '(' => 'T_OPEN_PARENTHESIS', |
|
170 | - ')' => 'T_CLOSE_PARENTHESIS', |
|
171 | - '{' => 'T_OPEN_CURLY_BRACKET', |
|
172 | - '}' => 'T_CLOSE_CURLY_BRACKET', |
|
173 | - '[' => 'T_OPEN_SQUARE_BRACKET', |
|
174 | - ']' => 'T_CLOSE_SQUARE_BRACKET', |
|
175 | - '?' => 'T_INLINE_THEN', |
|
176 | - '.' => 'T_OBJECT_OPERATOR', |
|
177 | - '+' => 'T_PLUS', |
|
178 | - '-' => 'T_MINUS', |
|
179 | - '*' => 'T_MULTIPLY', |
|
180 | - '%' => 'T_MODULUS', |
|
181 | - '/' => 'T_DIVIDE', |
|
182 | - '^' => 'T_LOGICAL_XOR', |
|
183 | - ',' => 'T_COMMA', |
|
184 | - ';' => 'T_SEMICOLON', |
|
185 | - ':' => 'T_COLON', |
|
186 | - '<' => 'T_LESS_THAN', |
|
187 | - '>' => 'T_GREATER_THAN', |
|
188 | - '<=' => 'T_IS_SMALLER_OR_EQUAL', |
|
189 | - '>=' => 'T_IS_GREATER_OR_EQUAL', |
|
190 | - '!' => 'T_BOOLEAN_NOT', |
|
191 | - '||' => 'T_BOOLEAN_OR', |
|
192 | - '&&' => 'T_BOOLEAN_AND', |
|
193 | - '|' => 'T_BITWISE_OR', |
|
194 | - '&' => 'T_BITWISE_AND', |
|
195 | - '!=' => 'T_IS_NOT_EQUAL', |
|
196 | - '!==' => 'T_IS_NOT_IDENTICAL', |
|
197 | - '=' => 'T_EQUAL', |
|
198 | - '==' => 'T_IS_EQUAL', |
|
199 | - '===' => 'T_IS_IDENTICAL', |
|
200 | - '-=' => 'T_MINUS_EQUAL', |
|
201 | - '+=' => 'T_PLUS_EQUAL', |
|
202 | - '*=' => 'T_MUL_EQUAL', |
|
203 | - '/=' => 'T_DIV_EQUAL', |
|
204 | - '%=' => 'T_MOD_EQUAL', |
|
205 | - '++' => 'T_INC', |
|
206 | - '--' => 'T_DEC', |
|
207 | - '//' => 'T_COMMENT', |
|
208 | - '/*' => 'T_COMMENT', |
|
209 | - '/**' => 'T_DOC_COMMENT', |
|
210 | - '*/' => 'T_COMMENT', |
|
211 | - ); |
|
147 | + 'function' => 'T_FUNCTION', |
|
148 | + 'prototype' => 'T_PROTOTYPE', |
|
149 | + 'try' => 'T_TRY', |
|
150 | + 'catch' => 'T_CATCH', |
|
151 | + 'return' => 'T_RETURN', |
|
152 | + 'throw' => 'T_THROW', |
|
153 | + 'break' => 'T_BREAK', |
|
154 | + 'switch' => 'T_SWITCH', |
|
155 | + 'continue' => 'T_CONTINUE', |
|
156 | + 'if' => 'T_IF', |
|
157 | + 'else' => 'T_ELSE', |
|
158 | + 'do' => 'T_DO', |
|
159 | + 'while' => 'T_WHILE', |
|
160 | + 'for' => 'T_FOR', |
|
161 | + 'var' => 'T_VAR', |
|
162 | + 'case' => 'T_CASE', |
|
163 | + 'default' => 'T_DEFAULT', |
|
164 | + 'true' => 'T_TRUE', |
|
165 | + 'false' => 'T_FALSE', |
|
166 | + 'null' => 'T_NULL', |
|
167 | + 'this' => 'T_THIS', |
|
168 | + 'typeof' => 'T_TYPEOF', |
|
169 | + '(' => 'T_OPEN_PARENTHESIS', |
|
170 | + ')' => 'T_CLOSE_PARENTHESIS', |
|
171 | + '{' => 'T_OPEN_CURLY_BRACKET', |
|
172 | + '}' => 'T_CLOSE_CURLY_BRACKET', |
|
173 | + '[' => 'T_OPEN_SQUARE_BRACKET', |
|
174 | + ']' => 'T_CLOSE_SQUARE_BRACKET', |
|
175 | + '?' => 'T_INLINE_THEN', |
|
176 | + '.' => 'T_OBJECT_OPERATOR', |
|
177 | + '+' => 'T_PLUS', |
|
178 | + '-' => 'T_MINUS', |
|
179 | + '*' => 'T_MULTIPLY', |
|
180 | + '%' => 'T_MODULUS', |
|
181 | + '/' => 'T_DIVIDE', |
|
182 | + '^' => 'T_LOGICAL_XOR', |
|
183 | + ',' => 'T_COMMA', |
|
184 | + ';' => 'T_SEMICOLON', |
|
185 | + ':' => 'T_COLON', |
|
186 | + '<' => 'T_LESS_THAN', |
|
187 | + '>' => 'T_GREATER_THAN', |
|
188 | + '<=' => 'T_IS_SMALLER_OR_EQUAL', |
|
189 | + '>=' => 'T_IS_GREATER_OR_EQUAL', |
|
190 | + '!' => 'T_BOOLEAN_NOT', |
|
191 | + '||' => 'T_BOOLEAN_OR', |
|
192 | + '&&' => 'T_BOOLEAN_AND', |
|
193 | + '|' => 'T_BITWISE_OR', |
|
194 | + '&' => 'T_BITWISE_AND', |
|
195 | + '!=' => 'T_IS_NOT_EQUAL', |
|
196 | + '!==' => 'T_IS_NOT_IDENTICAL', |
|
197 | + '=' => 'T_EQUAL', |
|
198 | + '==' => 'T_IS_EQUAL', |
|
199 | + '===' => 'T_IS_IDENTICAL', |
|
200 | + '-=' => 'T_MINUS_EQUAL', |
|
201 | + '+=' => 'T_PLUS_EQUAL', |
|
202 | + '*=' => 'T_MUL_EQUAL', |
|
203 | + '/=' => 'T_DIV_EQUAL', |
|
204 | + '%=' => 'T_MOD_EQUAL', |
|
205 | + '++' => 'T_INC', |
|
206 | + '--' => 'T_DEC', |
|
207 | + '//' => 'T_COMMENT', |
|
208 | + '/*' => 'T_COMMENT', |
|
209 | + '/**' => 'T_DOC_COMMENT', |
|
210 | + '*/' => 'T_COMMENT', |
|
211 | + ); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * A list string delimiters. |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @var array |
217 | 217 | */ |
218 | 218 | protected $stringTokens = array( |
219 | - '\'' => '\'', |
|
220 | - '"' => '"', |
|
221 | - ); |
|
219 | + '\'' => '\'', |
|
220 | + '"' => '"', |
|
221 | + ); |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * A list tokens that start and end comments. |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | '//' => null, |
230 | 230 | '/*' => '*/', |
231 | 231 | '/**' => '*/', |
232 | - ); |
|
232 | + ); |
|
233 | 233 | |
234 | 234 | |
235 | 235 | /** |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | $commentTokenizer = new Comment(); |
290 | 290 | |
291 | 291 | $tokens[] = array( |
292 | - 'code' => T_OPEN_TAG, |
|
293 | - 'type' => 'T_OPEN_TAG', |
|
294 | - 'content' => '', |
|
292 | + 'code' => T_OPEN_TAG, |
|
293 | + 'type' => 'T_OPEN_TAG', |
|
294 | + 'content' => '', |
|
295 | 295 | ); |
296 | 296 | |
297 | 297 | // Convert newlines to single characters for ease of |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | // add a character, store the whitespace first. |
324 | 324 | if (trim($char) !== '' && trim($buffer) === '') { |
325 | 325 | $tokens[] = array( |
326 | - 'code' => T_WHITESPACE, |
|
327 | - 'type' => 'T_WHITESPACE', |
|
328 | - 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
326 | + 'code' => T_WHITESPACE, |
|
327 | + 'type' => 'T_WHITESPACE', |
|
328 | + 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
329 | 329 | ); |
330 | 330 | |
331 | 331 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | && trim($buffer) !== '' |
345 | 345 | ) { |
346 | 346 | $tokens[] = array( |
347 | - 'code' => T_STRING, |
|
348 | - 'type' => 'T_STRING', |
|
349 | - 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
347 | + 'code' => T_STRING, |
|
348 | + 'type' => 'T_STRING', |
|
349 | + 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
350 | 350 | ); |
351 | 351 | |
352 | 352 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -376,9 +376,9 @@ discard block |
||
376 | 376 | // There is an even number escape chars, |
377 | 377 | // so this is not escaped, it is the end of the string. |
378 | 378 | $tokens[] = array( |
379 | - 'code' => T_CONSTANT_ENCAPSED_STRING, |
|
380 | - 'type' => 'T_CONSTANT_ENCAPSED_STRING', |
|
381 | - 'content' => str_replace("\n", $this->eolChar, $buffer).$char, |
|
379 | + 'code' => T_CONSTANT_ENCAPSED_STRING, |
|
380 | + 'type' => 'T_CONSTANT_ENCAPSED_STRING', |
|
381 | + 'content' => str_replace("\n", $this->eolChar, $buffer).$char, |
|
382 | 382 | ); |
383 | 383 | |
384 | 384 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -444,9 +444,9 @@ discard block |
||
444 | 444 | |
445 | 445 | if ($regex !== null) { |
446 | 446 | $tokens[] = array( |
447 | - 'code' => T_REGULAR_EXPRESSION, |
|
448 | - 'type' => 'T_REGULAR_EXPRESSION', |
|
449 | - 'content' => $regex['content'], |
|
447 | + 'code' => T_REGULAR_EXPRESSION, |
|
448 | + 'type' => 'T_REGULAR_EXPRESSION', |
|
449 | + 'content' => $regex['content'], |
|
450 | 450 | ); |
451 | 451 | |
452 | 452 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | |
527 | 527 | $value = $this->tokenValues[strtolower($buffer)]; |
528 | 528 | $tokens[] = array( |
529 | - 'code' => constant($value), |
|
530 | - 'type' => $value, |
|
531 | - 'content' => $buffer, |
|
529 | + 'code' => constant($value), |
|
530 | + 'type' => $value, |
|
531 | + 'content' => $buffer, |
|
532 | 532 | ); |
533 | 533 | |
534 | 534 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -545,9 +545,9 @@ discard block |
||
545 | 545 | $newContent = substr(str_replace("\n", $this->eolChar, $buffer), 0, -1); |
546 | 546 | if ($newContent !== '') { |
547 | 547 | $tokens[] = array( |
548 | - 'code' => T_STRING, |
|
549 | - 'type' => 'T_STRING', |
|
550 | - 'content' => $newContent, |
|
548 | + 'code' => T_STRING, |
|
549 | + 'type' => 'T_STRING', |
|
550 | + 'content' => $newContent, |
|
551 | 551 | ); |
552 | 552 | |
553 | 553 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -593,9 +593,9 @@ discard block |
||
593 | 593 | if ($matchedToken === false) { |
594 | 594 | $value = $this->tokenValues[strtolower($char)]; |
595 | 595 | $tokens[] = array( |
596 | - 'code' => constant($value), |
|
597 | - 'type' => $value, |
|
598 | - 'content' => $char, |
|
596 | + 'code' => constant($value), |
|
597 | + 'type' => $value, |
|
598 | + 'content' => $char, |
|
599 | 599 | ); |
600 | 600 | |
601 | 601 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -631,9 +631,9 @@ discard block |
||
631 | 631 | $lastChar = $lastChars[$x]; |
632 | 632 | $value = $this->tokenValues[strtolower($lastChar)]; |
633 | 633 | $tokens[] = array( |
634 | - 'code' => constant($value), |
|
635 | - 'type' => $value, |
|
636 | - 'content' => $lastChar, |
|
634 | + 'code' => constant($value), |
|
635 | + 'type' => $value, |
|
636 | + 'content' => $lastChar, |
|
637 | 637 | ); |
638 | 638 | |
639 | 639 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -669,9 +669,9 @@ discard block |
||
669 | 669 | |
670 | 670 | if ($inComment === '' && $cleanBuffer === false) { |
671 | 671 | $tokens[] = array( |
672 | - 'code' => T_STRING, |
|
673 | - 'type' => 'T_STRING', |
|
674 | - 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
672 | + 'code' => T_STRING, |
|
673 | + 'type' => 'T_STRING', |
|
674 | + 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
675 | 675 | ); |
676 | 676 | |
677 | 677 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -692,9 +692,9 @@ discard block |
||
692 | 692 | if (empty($buffer) === false) { |
693 | 693 | // Buffer contains whitespace from the end of the file. |
694 | 694 | $tokens[] = array( |
695 | - 'code' => T_WHITESPACE, |
|
696 | - 'type' => 'T_WHITESPACE', |
|
697 | - 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
695 | + 'code' => T_WHITESPACE, |
|
696 | + 'type' => 'T_WHITESPACE', |
|
697 | + 'content' => str_replace("\n", $this->eolChar, $buffer), |
|
698 | 698 | ); |
699 | 699 | |
700 | 700 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
@@ -704,9 +704,9 @@ discard block |
||
704 | 704 | } |
705 | 705 | |
706 | 706 | $tokens[] = array( |
707 | - 'code' => T_CLOSE_TAG, |
|
708 | - 'type' => 'T_CLOSE_TAG', |
|
709 | - 'content' => '', |
|
707 | + 'code' => T_CLOSE_TAG, |
|
708 | + 'type' => 'T_CLOSE_TAG', |
|
709 | + 'content' => '', |
|
710 | 710 | ); |
711 | 711 | |
712 | 712 | /* |
@@ -884,19 +884,19 @@ discard block |
||
884 | 884 | public function getRegexToken($char, $string, $chars, $tokens) |
885 | 885 | { |
886 | 886 | $beforeTokens = array( |
887 | - T_EQUAL => true, |
|
888 | - T_OPEN_PARENTHESIS => true, |
|
889 | - T_OPEN_SQUARE_BRACKET => true, |
|
890 | - T_RETURN => true, |
|
891 | - T_BOOLEAN_OR => true, |
|
892 | - T_BOOLEAN_AND => true, |
|
893 | - T_BITWISE_OR => true, |
|
894 | - T_BITWISE_AND => true, |
|
895 | - T_COMMA => true, |
|
896 | - T_COLON => true, |
|
897 | - T_TYPEOF => true, |
|
898 | - T_INLINE_THEN => true, |
|
899 | - T_INLINE_ELSE => true, |
|
887 | + T_EQUAL => true, |
|
888 | + T_OPEN_PARENTHESIS => true, |
|
889 | + T_OPEN_SQUARE_BRACKET => true, |
|
890 | + T_RETURN => true, |
|
891 | + T_BOOLEAN_OR => true, |
|
892 | + T_BOOLEAN_AND => true, |
|
893 | + T_BITWISE_OR => true, |
|
894 | + T_BITWISE_AND => true, |
|
895 | + T_COMMA => true, |
|
896 | + T_COLON => true, |
|
897 | + T_TYPEOF => true, |
|
898 | + T_INLINE_THEN => true, |
|
899 | + T_INLINE_ELSE => true, |
|
900 | 900 | ); |
901 | 901 | |
902 | 902 | $afterTokens = array( |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | '.' => true, |
909 | 909 | ':' => true, |
910 | 910 | $this->eolChar => true, |
911 | - ); |
|
911 | + ); |
|
912 | 912 | |
913 | 913 | // Find the last non-whitespace token that was added |
914 | 914 | // to the tokens array. |
@@ -997,10 +997,10 @@ discard block |
||
997 | 997 | } |
998 | 998 | |
999 | 999 | $token = array( |
1000 | - 'start' => $char, |
|
1001 | - 'end' => $regexEnd, |
|
1002 | - 'content' => $content, |
|
1003 | - ); |
|
1000 | + 'start' => $char, |
|
1001 | + 'end' => $regexEnd, |
|
1002 | + 'content' => $content, |
|
1003 | + ); |
|
1004 | 1004 | |
1005 | 1005 | return $token; |
1006 | 1006 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @return void |
30 | 30 | * @throws TokenizerException If the file appears to be minified. |
31 | 31 | */ |
32 | - public function __construct($content, Config $config, $eolChar='\n') |
|
32 | + public function __construct($content, Config $config, $eolChar = '\n') |
|
33 | 33 | { |
34 | 34 | if ($this->isMinifiedContent($content, $eolChar) === true) { |
35 | 35 | throw new TokenizerException('File appears to be minified and cannot be processed'); |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | $string = ltrim($string, '/*'); |
59 | 59 | |
60 | 60 | $tokens[$stackPtr] = array( |
61 | - 'content' => $openTag, |
|
62 | - 'code' => T_DOC_COMMENT_OPEN_TAG, |
|
63 | - 'type' => 'T_DOC_COMMENT_OPEN_TAG', |
|
64 | - 'comment_tags' => array(), |
|
65 | - ); |
|
61 | + 'content' => $openTag, |
|
62 | + 'code' => T_DOC_COMMENT_OPEN_TAG, |
|
63 | + 'type' => 'T_DOC_COMMENT_OPEN_TAG', |
|
64 | + 'comment_tags' => array(), |
|
65 | + ); |
|
66 | 66 | |
67 | 67 | $openPtr = $stackPtr; |
68 | 68 | $stackPtr++; |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | */ |
80 | 80 | |
81 | 81 | $closeTag = array( |
82 | - 'content' => substr($string, strlen(rtrim($string, '/*'))), |
|
83 | - 'code' => T_DOC_COMMENT_CLOSE_TAG, |
|
84 | - 'type' => 'T_DOC_COMMENT_CLOSE_TAG', |
|
85 | - 'comment_opener' => $openPtr, |
|
82 | + 'content' => substr($string, strlen(rtrim($string, '/*'))), |
|
83 | + 'code' => T_DOC_COMMENT_CLOSE_TAG, |
|
84 | + 'type' => 'T_DOC_COMMENT_CLOSE_TAG', |
|
85 | + 'comment_opener' => $openPtr, |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | $string = rtrim($string, '/*'); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | // This is a function or class doc block line. |
126 | 126 | $char++; |
127 | 127 | $tokens[$stackPtr] = array( |
128 | - 'content' => '*', |
|
129 | - 'code' => T_DOC_COMMENT_STAR, |
|
130 | - 'type' => 'T_DOC_COMMENT_STAR', |
|
131 | - ); |
|
128 | + 'content' => '*', |
|
129 | + 'code' => T_DOC_COMMENT_STAR, |
|
130 | + 'type' => 'T_DOC_COMMENT_STAR', |
|
131 | + ); |
|
132 | 132 | |
133 | 133 | $stackPtr++; |
134 | 134 | |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | $tagName = $matches[0]; |
205 | 205 | $start += strlen($tagName); |
206 | 206 | $tokens[] = array( |
207 | - 'content' => $tagName, |
|
208 | - 'code' => T_DOC_COMMENT_TAG, |
|
209 | - 'type' => 'T_DOC_COMMENT_TAG', |
|
207 | + 'content' => $tagName, |
|
208 | + 'code' => T_DOC_COMMENT_TAG, |
|
209 | + 'type' => 'T_DOC_COMMENT_TAG', |
|
210 | 210 | ); |
211 | 211 | |
212 | 212 | // Then there will be some whitespace. |
@@ -226,17 +226,17 @@ discard block |
||
226 | 226 | |
227 | 227 | if ($eol > $start) { |
228 | 228 | $tokens[] = array( |
229 | - 'content' => substr($string, $start, ($eol - $start)), |
|
230 | - 'code' => T_DOC_COMMENT_STRING, |
|
231 | - 'type' => 'T_DOC_COMMENT_STRING', |
|
229 | + 'content' => substr($string, $start, ($eol - $start)), |
|
230 | + 'code' => T_DOC_COMMENT_STRING, |
|
231 | + 'type' => 'T_DOC_COMMENT_STRING', |
|
232 | 232 | ); |
233 | 233 | } |
234 | 234 | |
235 | 235 | if ($eol !== $end) { |
236 | 236 | $tokens[] = array( |
237 | - 'content' => substr($string, $eol, strlen($eolChar)), |
|
238 | - 'code' => T_DOC_COMMENT_WHITESPACE, |
|
239 | - 'type' => 'T_DOC_COMMENT_WHITESPACE', |
|
237 | + 'content' => substr($string, $eol, strlen($eolChar)), |
|
238 | + 'code' => T_DOC_COMMENT_WHITESPACE, |
|
239 | + 'type' => 'T_DOC_COMMENT_WHITESPACE', |
|
240 | 240 | ); |
241 | 241 | } |
242 | 242 | |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | $token = array( |
273 | - 'content' => $space, |
|
274 | - 'code' => T_DOC_COMMENT_WHITESPACE, |
|
275 | - 'type' => 'T_DOC_COMMENT_WHITESPACE', |
|
276 | - ); |
|
273 | + 'content' => $space, |
|
274 | + 'code' => T_DOC_COMMENT_WHITESPACE, |
|
275 | + 'type' => 'T_DOC_COMMENT_WHITESPACE', |
|
276 | + ); |
|
277 | 277 | |
278 | 278 | return $token; |
279 | 279 |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | |
69 | 69 | $finalTokens = array(); |
70 | 70 | $finalTokens[0] = array( |
71 | - 'code' => T_OPEN_TAG, |
|
72 | - 'type' => 'T_OPEN_TAG', |
|
73 | - 'content' => '', |
|
74 | - ); |
|
71 | + 'code' => T_OPEN_TAG, |
|
72 | + 'type' => 'T_OPEN_TAG', |
|
73 | + 'content' => '', |
|
74 | + ); |
|
75 | 75 | |
76 | 76 | $newStackPtr = 1; |
77 | 77 | $numTokens = count($tokens); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | $finalTokens[$newStackPtr] = array( |
127 | - 'type' => 'T_EMBEDDED_PHP', |
|
128 | - 'code' => T_EMBEDDED_PHP, |
|
129 | - 'content' => $content, |
|
130 | - ); |
|
127 | + 'type' => 'T_EMBEDDED_PHP', |
|
128 | + 'code' => T_EMBEDDED_PHP, |
|
129 | + 'content' => $content, |
|
130 | + ); |
|
131 | 131 | |
132 | 132 | $newStackPtr++; |
133 | 133 | continue; |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | // Convert these back to T_STRING followed by T_COLON so we can |
138 | 138 | // more easily process style definitions. |
139 | 139 | $finalTokens[$newStackPtr] = array( |
140 | - 'type' => 'T_STRING', |
|
141 | - 'code' => T_STRING, |
|
142 | - 'content' => substr($token['content'], 0, -1), |
|
143 | - ); |
|
140 | + 'type' => 'T_STRING', |
|
141 | + 'code' => T_STRING, |
|
142 | + 'content' => substr($token['content'], 0, -1), |
|
143 | + ); |
|
144 | 144 | $newStackPtr++; |
145 | 145 | $finalTokens[$newStackPtr] = array( |
146 | - 'type' => 'T_COLON', |
|
147 | - 'code' => T_COLON, |
|
148 | - 'content' => ':', |
|
149 | - ); |
|
146 | + 'type' => 'T_COLON', |
|
147 | + 'code' => T_COLON, |
|
148 | + 'content' => ':', |
|
149 | + ); |
|
150 | 150 | $newStackPtr++; |
151 | 151 | continue; |
152 | 152 | } |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | if ($token['code'] === T_FUNCTION) { |
155 | 155 | // There are no functions in CSS, so convert this to a string. |
156 | 156 | $finalTokens[$newStackPtr] = array( |
157 | - 'type' => 'T_STRING', |
|
158 | - 'code' => T_STRING, |
|
159 | - 'content' => $token['content'], |
|
160 | - ); |
|
157 | + 'type' => 'T_STRING', |
|
158 | + 'code' => T_STRING, |
|
159 | + 'content' => $token['content'], |
|
160 | + ); |
|
161 | 161 | |
162 | 162 | $newStackPtr++; |
163 | 163 | continue; |
@@ -221,23 +221,23 @@ discard block |
||
221 | 221 | // Work out what we trimmed off above and remember to re-add it. |
222 | 222 | $trimmed = substr($token['content'], 0, (strlen($token['content']) - strlen($content))); |
223 | 223 | $finalTokens[$newStackPtr] = array( |
224 | - 'type' => 'T_COLOUR', |
|
225 | - 'code' => T_COLOUR, |
|
226 | - 'content' => $trimmed.$firstContent, |
|
227 | - ); |
|
224 | + 'type' => 'T_COLOUR', |
|
225 | + 'code' => T_COLOUR, |
|
226 | + 'content' => $trimmed.$firstContent, |
|
227 | + ); |
|
228 | 228 | } else { |
229 | 229 | $finalTokens[$newStackPtr] = array( |
230 | - 'type' => 'T_HASH', |
|
231 | - 'code' => T_HASH, |
|
232 | - 'content' => '#', |
|
233 | - ); |
|
230 | + 'type' => 'T_HASH', |
|
231 | + 'code' => T_HASH, |
|
232 | + 'content' => '#', |
|
233 | + ); |
|
234 | 234 | } |
235 | 235 | } else { |
236 | 236 | $finalTokens[$newStackPtr] = array( |
237 | - 'type' => 'T_STRING', |
|
238 | - 'code' => T_STRING, |
|
239 | - 'content' => '//', |
|
240 | - ); |
|
237 | + 'type' => 'T_STRING', |
|
238 | + 'code' => T_STRING, |
|
239 | + 'content' => '//', |
|
240 | + ); |
|
241 | 241 | }//end if |
242 | 242 | |
243 | 243 | $newStackPtr++; |
@@ -284,12 +284,32 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | switch ($token['code']) { |
287 | - case T_OPEN_CURLY_BRACKET: |
|
288 | - // Opening curly brackets for an At-rule do not start a style |
|
289 | - // definition. We also reset the asperand flag here because the next |
|
290 | - // opening curly bracket could be indeed the start of a style |
|
291 | - // definition. |
|
292 | - if ($asperandStart === true) { |
|
287 | + case T_OPEN_CURLY_BRACKET: |
|
288 | + // Opening curly brackets for an At-rule do not start a style |
|
289 | + // definition. We also reset the asperand flag here because the next |
|
290 | + // opening curly bracket could be indeed the start of a style |
|
291 | + // definition. |
|
292 | + if ($asperandStart === true) { |
|
293 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
294 | + if ($inStyleDef === true) { |
|
295 | + echo "\t\t* style definition closed *".PHP_EOL; |
|
296 | + } |
|
297 | + |
|
298 | + if ($asperandStart === true) { |
|
299 | + echo "\t\t* at-rule definition closed *".PHP_EOL; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + $inStyleDef = false; |
|
304 | + $asperandStart = false; |
|
305 | + } else { |
|
306 | + $inStyleDef = true; |
|
307 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
308 | + echo "\t\t* style definition opened *".PHP_EOL; |
|
309 | + } |
|
310 | + } |
|
311 | + break; |
|
312 | + case T_CLOSE_CURLY_BRACKET: |
|
293 | 313 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
294 | 314 | if ($inStyleDef === true) { |
295 | 315 | echo "\t\t* style definition closed *".PHP_EOL; |
@@ -302,162 +322,142 @@ discard block |
||
302 | 322 | |
303 | 323 | $inStyleDef = false; |
304 | 324 | $asperandStart = false; |
305 | - } else { |
|
306 | - $inStyleDef = true; |
|
307 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
308 | - echo "\t\t* style definition opened *".PHP_EOL; |
|
309 | - } |
|
310 | - } |
|
311 | - break; |
|
312 | - case T_CLOSE_CURLY_BRACKET: |
|
313 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
314 | - if ($inStyleDef === true) { |
|
315 | - echo "\t\t* style definition closed *".PHP_EOL; |
|
316 | - } |
|
317 | - |
|
318 | - if ($asperandStart === true) { |
|
319 | - echo "\t\t* at-rule definition closed *".PHP_EOL; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - $inStyleDef = false; |
|
324 | - $asperandStart = false; |
|
325 | - break; |
|
326 | - case T_MINUS: |
|
327 | - // Minus signs are often used instead of spaces inside |
|
328 | - // class names, IDs and styles. |
|
329 | - if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) { |
|
330 | - if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) { |
|
331 | - $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content']; |
|
332 | - |
|
325 | + break; |
|
326 | + case T_MINUS: |
|
327 | + // Minus signs are often used instead of spaces inside |
|
328 | + // class names, IDs and styles. |
|
329 | + if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) { |
|
330 | + if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) { |
|
331 | + $newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content']; |
|
332 | + |
|
333 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
334 | + echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; |
|
335 | + $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
336 | + $new = Util\Common::prepareForOutput($newContent); |
|
337 | + echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; |
|
338 | + } |
|
339 | + |
|
340 | + $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
341 | + unset($finalTokens[$stackPtr]); |
|
342 | + unset($finalTokens[($stackPtr - 1)]); |
|
343 | + } else { |
|
344 | + $newContent = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
345 | + |
|
346 | + $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
347 | + unset($finalTokens[$stackPtr]); |
|
348 | + } |
|
349 | + } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) { |
|
350 | + // They can also be used to provide negative numbers. |
|
333 | 351 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
334 | - echo "\t\t* token is a string joiner; ignoring this and previous token".PHP_EOL; |
|
335 | - $old = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
336 | - $new = Util\Common::prepareForOutput($newContent); |
|
337 | - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$old\" to \"$new\"".PHP_EOL; |
|
352 | + echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL; |
|
353 | + $content = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
354 | + echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL; |
|
338 | 355 | } |
339 | 356 | |
340 | - $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
357 | + $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
341 | 358 | unset($finalTokens[$stackPtr]); |
342 | - unset($finalTokens[($stackPtr - 1)]); |
|
343 | - } else { |
|
344 | - $newContent = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
359 | + }//end if |
|
345 | 360 | |
346 | - $finalTokens[($stackPtr + 1)]['content'] = $newContent; |
|
347 | - unset($finalTokens[$stackPtr]); |
|
348 | - } |
|
349 | - } else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) { |
|
350 | - // They can also be used to provide negative numbers. |
|
351 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
352 | - echo "\t\t* token is part of a negative number; adding content to next token and ignoring *".PHP_EOL; |
|
353 | - $content = Util\Common::prepareForOutput($finalTokens[($stackPtr + 1)]['content']); |
|
354 | - echo "\t\t=> token ".($stackPtr + 1)." content changed from \"$content\" to \"-$content\"".PHP_EOL; |
|
355 | - } |
|
356 | - |
|
357 | - $finalTokens[($stackPtr + 1)]['content'] = '-'.$finalTokens[($stackPtr + 1)]['content']; |
|
358 | - unset($finalTokens[$stackPtr]); |
|
359 | - }//end if |
|
360 | - |
|
361 | - break; |
|
362 | - case T_COLON: |
|
363 | - // Only interested in colons that are defining styles. |
|
364 | - if ($inStyleDef === false) { |
|
365 | 361 | break; |
366 | - } |
|
367 | - |
|
368 | - for ($x = ($stackPtr - 1); $x >= 0; $x--) { |
|
369 | - if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
|
362 | + case T_COLON: |
|
363 | + // Only interested in colons that are defining styles. |
|
364 | + if ($inStyleDef === false) { |
|
370 | 365 | break; |
371 | 366 | } |
372 | - } |
|
373 | 367 | |
374 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
375 | - $type = $finalTokens[$x]['type']; |
|
376 | - echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL; |
|
377 | - } |
|
378 | - |
|
379 | - $finalTokens[$x]['type'] = 'T_STYLE'; |
|
380 | - $finalTokens[$x]['code'] = T_STYLE; |
|
381 | - break; |
|
382 | - case T_STRING: |
|
383 | - if (strtolower($token['content']) === 'url') { |
|
384 | - // Find the next content. |
|
385 | - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { |
|
368 | + for ($x = ($stackPtr - 1); $x >= 0; $x--) { |
|
386 | 369 | if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
387 | 370 | break; |
388 | 371 | } |
389 | 372 | } |
390 | 373 | |
391 | - // Needs to be in the format "url(" for it to be a URL. |
|
392 | - if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) { |
|
393 | - continue; |
|
374 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
375 | + $type = $finalTokens[$x]['type']; |
|
376 | + echo "\t\t=> token $x changed from $type to T_STYLE".PHP_EOL; |
|
394 | 377 | } |
395 | 378 | |
396 | - // Make sure the content isn't empty. |
|
397 | - for ($y = ($x + 1); $y < $numTokens; $y++) { |
|
398 | - if (isset(Util\Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) { |
|
399 | - break; |
|
379 | + $finalTokens[$x]['type'] = 'T_STYLE'; |
|
380 | + $finalTokens[$x]['code'] = T_STYLE; |
|
381 | + break; |
|
382 | + case T_STRING: |
|
383 | + if (strtolower($token['content']) === 'url') { |
|
384 | + // Find the next content. |
|
385 | + for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { |
|
386 | + if (isset(Util\Tokens::$emptyTokens[$finalTokens[$x]['code']]) === false) { |
|
387 | + break; |
|
388 | + } |
|
400 | 389 | } |
401 | - } |
|
402 | 390 | |
403 | - if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) { |
|
404 | - continue; |
|
405 | - } |
|
406 | - |
|
407 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
408 | - for ($i = ($stackPtr + 1); $i <= $y; $i++) { |
|
409 | - $type = $finalTokens[$i]['type']; |
|
410 | - $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
411 | - echo "\tProcess token $i: $type => $content".PHP_EOL; |
|
391 | + // Needs to be in the format "url(" for it to be a URL. |
|
392 | + if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) { |
|
393 | + continue; |
|
412 | 394 | } |
413 | 395 | |
414 | - echo "\t\t* token starts a URL *".PHP_EOL; |
|
415 | - } |
|
396 | + // Make sure the content isn't empty. |
|
397 | + for ($y = ($x + 1); $y < $numTokens; $y++) { |
|
398 | + if (isset(Util\Tokens::$emptyTokens[$finalTokens[$y]['code']]) === false) { |
|
399 | + break; |
|
400 | + } |
|
401 | + } |
|
416 | 402 | |
417 | - // Join all the content together inside the url() statement. |
|
418 | - $newContent = ''; |
|
419 | - for ($i = ($x + 2); $i < $numTokens; $i++) { |
|
420 | - if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) { |
|
421 | - break; |
|
403 | + if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) { |
|
404 | + continue; |
|
422 | 405 | } |
423 | 406 | |
424 | - $newContent .= $finalTokens[$i]['content']; |
|
425 | 407 | if (PHP_CODESNIFFER_VERBOSITY > 1) { |
426 | - $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
427 | - echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL; |
|
408 | + for ($i = ($stackPtr + 1); $i <= $y; $i++) { |
|
409 | + $type = $finalTokens[$i]['type']; |
|
410 | + $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
411 | + echo "\tProcess token $i: $type => $content".PHP_EOL; |
|
412 | + } |
|
413 | + |
|
414 | + echo "\t\t* token starts a URL *".PHP_EOL; |
|
428 | 415 | } |
429 | 416 | |
430 | - unset($finalTokens[$i]); |
|
431 | - } |
|
417 | + // Join all the content together inside the url() statement. |
|
418 | + $newContent = ''; |
|
419 | + for ($i = ($x + 2); $i < $numTokens; $i++) { |
|
420 | + if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) { |
|
421 | + break; |
|
422 | + } |
|
432 | 423 | |
433 | - $stackPtr = $i; |
|
424 | + $newContent .= $finalTokens[$i]['content']; |
|
425 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
426 | + $content = Util\Common::prepareForOutput($finalTokens[$i]['content']); |
|
427 | + echo "\t\t=> token $i added to URL string and ignored: $content".PHP_EOL; |
|
428 | + } |
|
434 | 429 | |
435 | - // If the content inside the "url()" is in double quotes |
|
436 | - // there will only be one token and so we don't have to do |
|
437 | - // anything except change its type. If it is not empty, |
|
438 | - // we need to do some token merging. |
|
439 | - $finalTokens[($x + 1)]['type'] = 'T_URL'; |
|
440 | - $finalTokens[($x + 1)]['code'] = T_URL; |
|
430 | + unset($finalTokens[$i]); |
|
431 | + } |
|
441 | 432 | |
442 | - if ($newContent !== '') { |
|
443 | - $finalTokens[($x + 1)]['content'] .= $newContent; |
|
444 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
445 | - $content = Util\Common::prepareForOutput($finalTokens[($x + 1)]['content']); |
|
446 | - echo "\t\t=> token content changed to: $content".PHP_EOL; |
|
433 | + $stackPtr = $i; |
|
434 | + |
|
435 | + // If the content inside the "url()" is in double quotes |
|
436 | + // there will only be one token and so we don't have to do |
|
437 | + // anything except change its type. If it is not empty, |
|
438 | + // we need to do some token merging. |
|
439 | + $finalTokens[($x + 1)]['type'] = 'T_URL'; |
|
440 | + $finalTokens[($x + 1)]['code'] = T_URL; |
|
441 | + |
|
442 | + if ($newContent !== '') { |
|
443 | + $finalTokens[($x + 1)]['content'] .= $newContent; |
|
444 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
445 | + $content = Util\Common::prepareForOutput($finalTokens[($x + 1)]['content']); |
|
446 | + echo "\t\t=> token content changed to: $content".PHP_EOL; |
|
447 | + } |
|
447 | 448 | } |
448 | - } |
|
449 | - }//end if |
|
449 | + }//end if |
|
450 | 450 | |
451 | - break; |
|
452 | - case T_ASPERAND: |
|
453 | - $asperandStart = true; |
|
454 | - if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | - echo "\t\t* at-rule definition opened *".PHP_EOL; |
|
456 | - } |
|
457 | - break; |
|
458 | - default: |
|
459 | - // Nothing special to be done with this token. |
|
460 | - break; |
|
451 | + break; |
|
452 | + case T_ASPERAND: |
|
453 | + $asperandStart = true; |
|
454 | + if (PHP_CODESNIFFER_VERBOSITY > 1) { |
|
455 | + echo "\t\t* at-rule definition opened *".PHP_EOL; |
|
456 | + } |
|
457 | + break; |
|
458 | + default: |
|
459 | + // Nothing special to be done with this token. |
|
460 | + break; |
|
461 | 461 | }//end switch |
462 | 462 | }//end for |
463 | 463 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @return void |
30 | 30 | * @throws TokenizerException If the file appears to be minified. |
31 | 31 | */ |
32 | - public function __construct($content, Config $config, $eolChar='\n') |
|
32 | + public function __construct($content, Config $config, $eolChar = '\n') |
|
33 | 33 | { |
34 | 34 | if ($this->isMinifiedContent($content, $eolChar) === true) { |
35 | 35 | throw new TokenizerException('File appears to be minified and cannot be processed'); |