Skip to content

Commit 21ff518

Browse files
committed
Update
1 parent af05418 commit 21ff518

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

src/Fixer/ReadonlyPromotedPropertiesFixer.php

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222

2323
final class ReadonlyPromotedPropertiesFixer extends AbstractFixer
2424
{
25+
/** @var list<int> */
26+
private array $promotedPropertyVisibilityKinds;
27+
28+
public function __construct()
29+
{
30+
$this->promotedPropertyVisibilityKinds = [
31+
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE,
32+
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED,
33+
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC,
34+
];
35+
if (\defined('T_PUBLIC_SET')) {
36+
$this->promotedPropertyVisibilityKinds[] = \T_PUBLIC_SET;
37+
$this->promotedPropertyVisibilityKinds[] = \T_PROTECTED_SET;
38+
$this->promotedPropertyVisibilityKinds[] = \T_PRIVATE_SET;
39+
}
40+
}
41+
2542
public function getDefinition(): FixerDefinitionInterface
2643
{
2744
return new FixerDefinition(
@@ -53,7 +70,7 @@ public function getPriority(): int
5370

5471
public function isCandidate(Tokens $tokens): bool
5572
{
56-
return \defined('T_READONLY') && $tokens->isAnyTokenKindsFound(self::getPromotedPropertyVisibilityKinds());
73+
return \defined('T_READONLY') && $tokens->isAnyTokenKindsFound($this->promotedPropertyVisibilityKinds);
5774
}
5875

5976
public function isRisky(): bool
@@ -121,7 +138,7 @@ private function fixParameters(
121138
continue;
122139
}
123140

124-
$insertIndex = self::getInsertIndex($tokens, $index);
141+
$insertIndex = $this->getInsertIndex($tokens, $index);
125142
if ($insertIndex === null) {
126143
continue;
127144
}
@@ -149,7 +166,7 @@ private function fixParameters(
149166
}
150167
}
151168

152-
private static function getInsertIndex(Tokens $tokens, int $index): ?int
169+
private function getInsertIndex(Tokens $tokens, int $index): ?int
153170
{
154171
$insertIndex = null;
155172

@@ -161,35 +178,11 @@ private static function getInsertIndex(Tokens $tokens, int $index): ?int
161178
if ($tokens[$index]->isGivenKind(\T_READONLY)) {
162179
return null;
163180
}
164-
if ($insertIndex === null && $tokens[$index]->isGivenKind(self::getPromotedPropertyVisibilityKinds())) {
181+
if ($insertIndex === null && $tokens[$index]->isGivenKind($this->promotedPropertyVisibilityKinds)) {
165182
$insertIndex = $index;
166183
}
167184
}
168185

169186
return $insertIndex;
170187
}
171-
172-
/**
173-
* @return list<int>
174-
*/
175-
private static function getPromotedPropertyVisibilityKinds(): array
176-
{
177-
/** @var null|list<int> $promotedPropertyVisibilityKinds */
178-
static $promotedPropertyVisibilityKinds = null;
179-
180-
if ($promotedPropertyVisibilityKinds === null) {
181-
$promotedPropertyVisibilityKinds = [
182-
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE,
183-
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED,
184-
CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC,
185-
];
186-
if (\defined('T_PUBLIC_SET')) {
187-
$promotedPropertyVisibilityKinds[] = \T_PUBLIC_SET;
188-
$promotedPropertyVisibilityKinds[] = \T_PROTECTED_SET;
189-
$promotedPropertyVisibilityKinds[] = \T_PRIVATE_SET;
190-
}
191-
}
192-
193-
return $promotedPropertyVisibilityKinds;
194-
}
195188
}

0 commit comments

Comments
 (0)