|
14 | 14 | use PHP_CodeSniffer\Exceptions\TokenizerException;
|
15 | 15 | use PHP_CodeSniffer\Fixer;
|
16 | 16 | use PHP_CodeSniffer\Ruleset;
|
| 17 | +use PHP_CodeSniffer\Tokenizers\PHP; |
17 | 18 | use PHP_CodeSniffer\Util\Common;
|
18 | 19 | use PHP_CodeSniffer\Util\Tokens;
|
19 | 20 |
|
@@ -72,17 +73,10 @@ class File
|
72 | 73 | /**
|
73 | 74 | * The tokenizer being used for this file.
|
74 | 75 | *
|
75 |
| - * @var \PHP_CodeSniffer\Tokenizers\Tokenizer |
| 76 | + * @var \PHP_CodeSniffer\Tokenizers\PHP |
76 | 77 | */
|
77 | 78 | public $tokenizer = null;
|
78 | 79 |
|
79 |
| - /** |
80 |
| - * The name of the tokenizer being used for this file. |
81 |
| - * |
82 |
| - * @var string |
83 |
| - */ |
84 |
| - public $tokenizerType = 'PHP'; |
85 |
| - |
86 | 80 | /**
|
87 | 81 | * Was the file loaded from cache?
|
88 | 82 | *
|
@@ -240,15 +234,6 @@ public function __construct($path, Ruleset $ruleset, Config $config)
|
240 | 234 | $this->config = $config;
|
241 | 235 | $this->fixer = new Fixer();
|
242 | 236 |
|
243 |
| - $parts = explode('.', $path); |
244 |
| - $extension = array_pop($parts); |
245 |
| - if (isset($config->extensions[$extension]) === true) { |
246 |
| - $this->tokenizerType = $config->extensions[$extension]; |
247 |
| - } else { |
248 |
| - // Revert to default. |
249 |
| - $this->tokenizerType = 'PHP'; |
250 |
| - } |
251 |
| - |
252 | 237 | $this->configCache['cache'] = $this->config->cache;
|
253 | 238 | $this->configCache['sniffs'] = array_map('strtolower', $this->config->sniffs);
|
254 | 239 | $this->configCache['exclude'] = array_map('strtolower', $this->config->exclude);
|
@@ -412,14 +397,8 @@ public function process()
|
412 | 397 | continue;
|
413 | 398 | }
|
414 | 399 |
|
415 |
| - // Make sure this sniff supports the tokenizer |
416 |
| - // we are currently using. |
417 | 400 | $class = $listenerData['class'];
|
418 | 401 |
|
419 |
| - if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) { |
420 |
| - continue; |
421 |
| - } |
422 |
| - |
423 | 402 | if (trim($this->path, '\'"') !== 'STDIN') {
|
424 | 403 | // If the file path matches one of our ignore patterns, skip it.
|
425 | 404 | // While there is support for a type of each pattern
|
@@ -505,7 +484,7 @@ public function process()
|
505 | 484 | // We don't show this error for STDIN because we can't be sure the content
|
506 | 485 | // actually came directly from the user. It could be something like
|
507 | 486 | // refs from a Git pre-push hook.
|
508 |
| - if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') { |
| 487 | + if ($foundCode === false && $this->path !== 'STDIN') { |
509 | 488 | $shortTags = (bool) ini_get('short_open_tag');
|
510 | 489 | if ($shortTags === false) {
|
511 | 490 | $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
|
@@ -543,14 +522,13 @@ public function parse()
|
543 | 522 | }
|
544 | 523 |
|
545 | 524 | try {
|
546 |
| - $tokenizerClass = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType; |
547 |
| - $this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar); |
| 525 | + $this->tokenizer = new PHP($this->content, $this->config, $this->eolChar); |
548 | 526 | $this->tokens = $this->tokenizer->getTokens();
|
549 | 527 | } catch (TokenizerException $e) {
|
550 | 528 | $this->ignored = true;
|
551 | 529 | $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
|
552 | 530 | if (PHP_CODESNIFFER_VERBOSITY > 0) {
|
553 |
| - echo "[$this->tokenizerType => tokenizer error]... "; |
| 531 | + echo '[tokenizer error]... '; |
554 | 532 | if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
555 | 533 | echo PHP_EOL;
|
556 | 534 | }
|
@@ -582,7 +560,7 @@ public function parse()
|
582 | 560 | $numLines = $this->tokens[($this->numTokens - 1)]['line'];
|
583 | 561 | }
|
584 | 562 |
|
585 |
| - echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... "; |
| 563 | + echo "[$this->numTokens tokens in $numLines lines]... "; |
586 | 564 | if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
587 | 565 | echo PHP_EOL;
|
588 | 566 | }
|
@@ -1249,14 +1227,6 @@ public function getDeclarationName($stackPtr)
|
1249 | 1227 | throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
|
1250 | 1228 | }
|
1251 | 1229 |
|
1252 |
| - if ($tokenCode === T_FUNCTION |
1253 |
| - && strtolower($this->tokens[$stackPtr]['content']) !== 'function' |
1254 |
| - ) { |
1255 |
| - // This is a function declared without the "function" keyword. |
1256 |
| - // So this token is the function name. |
1257 |
| - return $this->tokens[$stackPtr]['content']; |
1258 |
| - } |
1259 |
| - |
1260 | 1230 | $stopPoint = $this->numTokens;
|
1261 | 1231 | if (isset($this->tokens[$stackPtr]['parenthesis_opener']) === true) {
|
1262 | 1232 | // For functions, stop searching at the parenthesis opener.
|
@@ -1637,22 +1607,20 @@ public function getMethodProperties($stackPtr)
|
1637 | 1607 |
|
1638 | 1608 | if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
|
1639 | 1609 | $valid = [
|
1640 |
| - T_PUBLIC => T_PUBLIC, |
1641 |
| - T_PRIVATE => T_PRIVATE, |
1642 |
| - T_PROTECTED => T_PROTECTED, |
1643 |
| - T_STATIC => T_STATIC, |
1644 |
| - T_FINAL => T_FINAL, |
1645 |
| - T_ABSTRACT => T_ABSTRACT, |
1646 |
| - T_WHITESPACE => T_WHITESPACE, |
1647 |
| - T_COMMENT => T_COMMENT, |
1648 |
| - T_DOC_COMMENT => T_DOC_COMMENT, |
| 1610 | + T_PUBLIC => T_PUBLIC, |
| 1611 | + T_PRIVATE => T_PRIVATE, |
| 1612 | + T_PROTECTED => T_PROTECTED, |
| 1613 | + T_STATIC => T_STATIC, |
| 1614 | + T_FINAL => T_FINAL, |
| 1615 | + T_ABSTRACT => T_ABSTRACT, |
| 1616 | + T_WHITESPACE => T_WHITESPACE, |
| 1617 | + T_COMMENT => T_COMMENT, |
1649 | 1618 | ];
|
1650 | 1619 | } else {
|
1651 | 1620 | $valid = [
|
1652 |
| - T_STATIC => T_STATIC, |
1653 |
| - T_WHITESPACE => T_WHITESPACE, |
1654 |
| - T_COMMENT => T_COMMENT, |
1655 |
| - T_DOC_COMMENT => T_DOC_COMMENT, |
| 1621 | + T_STATIC => T_STATIC, |
| 1622 | + T_WHITESPACE => T_WHITESPACE, |
| 1623 | + T_COMMENT => T_COMMENT, |
1656 | 1624 | ];
|
1657 | 1625 | }
|
1658 | 1626 |
|
@@ -2011,12 +1979,11 @@ public function getClassProperties($stackPtr)
|
2011 | 1979 | }
|
2012 | 1980 |
|
2013 | 1981 | $valid = [
|
2014 |
| - T_FINAL => T_FINAL, |
2015 |
| - T_ABSTRACT => T_ABSTRACT, |
2016 |
| - T_READONLY => T_READONLY, |
2017 |
| - T_WHITESPACE => T_WHITESPACE, |
2018 |
| - T_COMMENT => T_COMMENT, |
2019 |
| - T_DOC_COMMENT => T_DOC_COMMENT, |
| 1982 | + T_FINAL => T_FINAL, |
| 1983 | + T_ABSTRACT => T_ABSTRACT, |
| 1984 | + T_READONLY => T_READONLY, |
| 1985 | + T_WHITESPACE => T_WHITESPACE, |
| 1986 | + T_COMMENT => T_COMMENT, |
2020 | 1987 | ];
|
2021 | 1988 |
|
2022 | 1989 | $isAbstract = false;
|
|
0 commit comments