Skip to content

Commit 0e18ef7

Browse files
committed
Modernize: Generic/LowerCaseConstant: use class constant for constant array
1 parent b698f0c commit 0e18ef7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class LowerCaseConstantSniff implements Sniff
1919
/**
2020
* The tokens this sniff is targetting.
2121
*
22-
* @var array
22+
* @var array<int|string, int|string>
2323
*/
24-
private $targets = [
24+
private const TARGET_TOKENS = [
2525
T_TRUE => T_TRUE,
2626
T_FALSE => T_FALSE,
2727
T_NULL => T_NULL,
@@ -32,23 +32,19 @@ class LowerCaseConstantSniff implements Sniff
3232
*
3333
* @var array<int|string, int|string>
3434
*/
35-
private $propertyTypeTokens = [
35+
private const PROPERTY_TYPE_TOKENS = (Tokens::NAME_TOKENS + [
3636
T_CALLABLE => T_CALLABLE,
3737
T_SELF => T_SELF,
3838
T_PARENT => T_PARENT,
3939
T_FALSE => T_FALSE,
4040
T_TRUE => T_TRUE,
4141
T_NULL => T_NULL,
42-
T_STRING => T_STRING,
43-
T_NAME_QUALIFIED => T_NAME_QUALIFIED,
44-
T_NAME_FULLY_QUALIFIED => T_NAME_FULLY_QUALIFIED,
45-
T_NAME_RELATIVE => T_NAME_RELATIVE,
4642
T_TYPE_UNION => T_TYPE_UNION,
4743
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
4844
T_TYPE_OPEN_PARENTHESIS => T_TYPE_OPEN_PARENTHESIS,
4945
T_TYPE_CLOSE_PARENTHESIS => T_TYPE_CLOSE_PARENTHESIS,
5046
T_NULLABLE => T_NULLABLE,
51-
];
47+
]);
5248

5349

5450
/**
@@ -58,7 +54,7 @@ class LowerCaseConstantSniff implements Sniff
5854
*/
5955
public function register()
6056
{
61-
$targets = $this->targets;
57+
$targets = self::TARGET_TOKENS;
6258

6359
// Register scope modifiers to filter out property type declarations.
6460
$targets += Tokens::SCOPE_MODIFIERS;
@@ -130,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
130126
|| $tokens[$stackPtr]['code'] === T_FINAL
131127
|| $tokens[$stackPtr]['code'] === T_ABSTRACT
132128
) {
133-
$skipOver = (Tokens::EMPTY_TOKENS + $this->propertyTypeTokens);
129+
$skipOver = (Tokens::EMPTY_TOKENS + self::PROPERTY_TYPE_TOKENS);
134130
$skipTo = $phpcsFile->findNext($skipOver, ($stackPtr + 1), null, true);
135131
if ($skipTo !== false) {
136132
return $skipTo;
@@ -161,7 +157,7 @@ public function process(File $phpcsFile, $stackPtr)
161157
}
162158

163159
// Do a quick check if any of the targets exist in the declaration.
164-
$found = $phpcsFile->findNext($this->targets, $tokens[$stackPtr]['parenthesis_opener'], $end);
160+
$found = $phpcsFile->findNext(self::TARGET_TOKENS, $tokens[$stackPtr]['parenthesis_opener'], $end);
165161
if ($found === false) {
166162
// Skip forward, no need to examine these tokens again.
167163
return $end;
@@ -180,7 +176,7 @@ public function process(File $phpcsFile, $stackPtr)
180176
}
181177

182178
for ($i = $param['default_token']; $i < $paramEnd; $i++) {
183-
if (isset($this->targets[$tokens[$i]['code']]) === true) {
179+
if (isset(self::TARGET_TOKENS[$tokens[$i]['code']]) === true) {
184180
$this->processConstant($phpcsFile, $i);
185181
}
186182
}

0 commit comments

Comments
 (0)