Skip to content

Commit 33a89dd

Browse files
committed
Modernize: PSR12/NullableTypeDeclaration: use class constant for constant array
1 parent 9e10aa1 commit 33a89dd

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,25 @@
1111

1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\Sniff;
14+
use PHP_CodeSniffer\Util\Tokens;
1415

1516
class NullableTypeDeclarationSniff implements Sniff
1617
{
1718

1819
/**
1920
* An array of valid tokens after `T_NULLABLE` occurrences.
2021
*
21-
* @var array
22+
* @var array<int|string, int|string>
2223
*/
23-
private $validTokens = [
24-
T_STRING => true,
25-
T_NAME_QUALIFIED => true,
26-
T_NAME_FULLY_QUALIFIED => true,
27-
T_NAME_RELATIVE => true,
28-
T_CALLABLE => true,
29-
T_SELF => true,
30-
T_PARENT => true,
31-
T_STATIC => true,
32-
T_NULL => true,
33-
T_FALSE => true,
34-
T_TRUE => true,
35-
];
24+
private const VALID_TOKENS = (Tokens::NAME_TOKENS + [
25+
T_CALLABLE => T_CALLABLE,
26+
T_SELF => T_SELF,
27+
T_PARENT => T_PARENT,
28+
T_STATIC => T_STATIC,
29+
T_NULL => T_NULL,
30+
T_FALSE => T_FALSE,
31+
T_TRUE => T_TRUE,
32+
]);
3633

3734

3835
/**
@@ -66,7 +63,7 @@ public function process(File $phpcsFile, $stackPtr)
6663

6764
$tokens = $phpcsFile->getTokens();
6865
$nextNonEmptyCode = $tokens[$nextNonEmptyPtr]['code'];
69-
$validTokenFound = isset($this->validTokens[$nextNonEmptyCode]);
66+
$validTokenFound = isset(self::VALID_TOKENS[$nextNonEmptyCode]);
7067

7168
if ($validTokenFound === true && $nextNonEmptyPtr === ($stackPtr + 1)) {
7269
// Valid structure.

0 commit comments

Comments
 (0)