comparison vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
35 * @var array 35 * @var array
36 */ 36 */
37 protected $tokens = []; 37 protected $tokens = [];
38 38
39 /** 39 /**
40 * The number of tokens in the tokens array.
41 *
42 * @var integer
43 */
44 protected $numTokens = 0;
45
46 /**
47 * A list of tokens that are allowed to open a scope.
48 *
49 * @var array
50 */
51 public $scopeOpeners = [];
52
53 /**
54 * A list of tokens that end the scope.
55 *
56 * @var array
57 */
58 public $endScopeTokens = [];
59
60 /**
40 * Known lengths of tokens. 61 * Known lengths of tokens.
41 * 62 *
42 * @var array<int, int> 63 * @var array<int, int>
43 */ 64 */
44 public $knownLengths = []; 65 public $knownLengths = [];
57 * @param string $content The content to tokenize, 78 * @param string $content The content to tokenize,
58 * @param \PHP_CodeSniffer\Config | null $config The config data for the run. 79 * @param \PHP_CodeSniffer\Config | null $config The config data for the run.
59 * @param string $eolChar The EOL char used in the content. 80 * @param string $eolChar The EOL char used in the content.
60 * 81 *
61 * @return void 82 * @return void
62 * @throws TokenizerException If the file appears to be minified. 83 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
63 */ 84 */
64 public function __construct($content, $config, $eolChar='\n') 85 public function __construct($content, $config, $eolChar='\n')
65 { 86 {
66 $this->eolChar = $eolChar; 87 $this->eolChar = $eolChar;
67 88
161 182
162 $checkAnnotations = $this->config->annotations; 183 $checkAnnotations = $this->config->annotations;
163 $encoding = $this->config->encoding; 184 $encoding = $this->config->encoding;
164 $tabWidth = $this->config->tabWidth; 185 $tabWidth = $this->config->tabWidth;
165 186
166 $this->tokensWithTabs = [ 187 $tokensWithTabs = [
167 T_WHITESPACE => true, 188 T_WHITESPACE => true,
168 T_COMMENT => true, 189 T_COMMENT => true,
169 T_DOC_COMMENT => true, 190 T_DOC_COMMENT => true,
170 T_DOC_COMMENT_WHITESPACE => true, 191 T_DOC_COMMENT_WHITESPACE => true,
171 T_DOC_COMMENT_STRING => true, 192 T_DOC_COMMENT_STRING => true,
184 if (isset($this->knownLengths[$this->tokens[$i]['code']]) === true) { 205 if (isset($this->knownLengths[$this->tokens[$i]['code']]) === true) {
185 // There are no tabs in the tokens we know the length of. 206 // There are no tabs in the tokens we know the length of.
186 $length = $this->knownLengths[$this->tokens[$i]['code']]; 207 $length = $this->knownLengths[$this->tokens[$i]['code']];
187 $currColumn += $length; 208 $currColumn += $length;
188 } else if ($tabWidth === 0 209 } else if ($tabWidth === 0
189 || isset($this->tokensWithTabs[$this->tokens[$i]['code']]) === false 210 || isset($tokensWithTabs[$this->tokens[$i]['code']]) === false
190 || strpos($this->tokens[$i]['content'], "\t") === false 211 || strpos($this->tokens[$i]['content'], "\t") === false
191 ) { 212 ) {
192 // There are no tabs in this content, or we aren't replacing them. 213 // There are no tabs in this content, or we aren't replacing them.
193 if ($checkEncoding === true) { 214 if ($checkEncoding === true) {
194 // Not using the default encoding, so take a bit more care. 215 // Not using the default encoding, so take a bit more care.
367 // Ignore standards for complete lines that change sniff settings. 388 // Ignore standards for complete lines that change sniff settings.
368 if ($lineHasOtherTokens === false) { 389 if ($lineHasOtherTokens === false) {
369 $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true]; 390 $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
370 } 391 }
371 392
393 // Need to maintain case here, to get the correct sniff code.
394 $parts = explode(' ', substr($commentText, 10));
395 if (count($parts) >= 2) {
396 $sniffParts = explode('.', $parts[0]);
397 if (count($sniffParts) >= 3) {
398 $this->tokens[$i]['sniffCode'] = array_shift($parts);
399 $this->tokens[$i]['sniffProperty'] = array_shift($parts);
400 $this->tokens[$i]['sniffPropertyValue'] = rtrim(implode(' ', $parts), " */\r\n");
401 }
402 }
403
372 $this->tokens[$i]['code'] = T_PHPCS_SET; 404 $this->tokens[$i]['code'] = T_PHPCS_SET;
373 $this->tokens[$i]['type'] = 'T_PHPCS_SET'; 405 $this->tokens[$i]['type'] = 'T_PHPCS_SET';
374 } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile') { 406 } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile') {
375 // The whole file will be ignored, but at least set the correct token. 407 // The whole file will be ignored, but at least set the correct token.
376 $this->tokens[$i]['code'] = T_PHPCS_IGNORE_FILE; 408 $this->tokens[$i]['code'] = T_PHPCS_IGNORE_FILE;
500 if ($ignoring !== null) { 532 if ($ignoring !== null) {
501 $ignoreRules += $ignoring; 533 $ignoreRules += $ignoring;
502 } 534 }
503 535
504 if ($lineHasOtherContent === false) { 536 if ($lineHasOtherContent === false) {
505 // Completely ignore the comment line, and set the folllowing 537 // Completely ignore the comment line, and set the following
506 // line to include the ignore rules we've set. 538 // line to include the ignore rules we've set.
507 $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true]; 539 $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
508 $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoreRules; 540 $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoreRules;
509 } else { 541 } else {
510 // The comment is on the same line as the code it is ignoring, 542 // The comment is on the same line as the code it is ignoring,