Skip to content

Commit f9b2bdb

Browse files
committed
AbstractArrayDeclarationSniff::getActualArrayKey(): minor simplification
The tokenization of fully qualified `true`/`false`/`null` has been changed for both PHPCS 3.x (as of 3.13.3) as well as PHPCS 4.0. The new tokenization means we don't need to take these tokens being tokenized as `T_STRING` or `T_NAME_FULLY_QUALIFIED` into account anymore, as long as the minimum supported PHPCS version will be PHPCS 3.13.3 (which it will be since the merge of PR 698). This commit removes the code which has now become redundant. Ref: * PHPCSStandards/PHP_CodeSniffer 1201 * PHPCSStandards/PHP_CodeSniffer 1206
1 parent 7ec8f55 commit f9b2bdb

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -478,31 +478,15 @@ public function getActualArrayKey(File $phpcsFile, $startPtr, $endPtr)
478478
continue;
479479
}
480480

481-
// Handle FQN true/false/null.
482-
if ($this->tokens[$i]['code'] === \T_NAME_FULLY_QUALIFIED) {
483-
$compareReadyKeyword = \strtolower($this->tokens[$i]['content']);
484-
if ($compareReadyKeyword === '\true'
485-
|| $compareReadyKeyword === '\false'
486-
|| $compareReadyKeyword === '\null'
487-
) {
488-
// FQN true/false/null on PHPCS 4.x. This can be handled.
489-
$content .= $this->tokens[$i]['content'];
490-
continue;
491-
}
492-
} elseif ($this->tokens[$i]['code'] === \T_NS_SEPARATOR) {
493-
// PHPCS 3.x.
481+
// Handle FQN true/false/null for PHPCS 3.x.
482+
if ($this->tokens[$i]['code'] === \T_NS_SEPARATOR) {
494483
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
495484
$nextNonEmptyLC = \strtolower($this->tokens[$nextNonEmpty]['content']);
496485
if ($nextNonEmpty !== false
497-
// PHPCS 3.x with PHP < 8.0.
498486
&& ($this->tokens[$nextNonEmpty]['code'] === \T_TRUE
499487
|| $this->tokens[$nextNonEmpty]['code'] === \T_FALSE
500-
|| $this->tokens[$nextNonEmpty]['code'] === \T_NULL
501-
// PHPCS 3.x with PHP >= 8.0 where the namespaced name tokenization has been undone.
502-
|| ($this->tokens[$nextNonEmpty]['code'] === \T_STRING
503-
&& ($nextNonEmptyLC === 'true' || $nextNonEmptyLC === 'false' || $nextNonEmptyLC === 'null')))
488+
|| $this->tokens[$nextNonEmpty]['code'] === \T_NULL)
504489
) {
505-
// FQN true/false/null on PHPCS 3.x. This can be handled.
506490
$content .= $this->tokens[$nextNonEmpty]['content'];
507491
$i = $nextNonEmpty;
508492
continue;

0 commit comments

Comments
 (0)