1616use PhpCsFixer \FixerDefinition \VersionSpecification ;
1717use PhpCsFixer \FixerDefinition \VersionSpecificCodeSample ;
1818use PhpCsFixer \Tokenizer \CT ;
19+ use PhpCsFixer \Tokenizer \FCT ;
1920use PhpCsFixer \Tokenizer \Token ;
2021use PhpCsFixer \Tokenizer \Tokens ;
2122use PhpCsFixerCustomFixers \Analyzer \ConstructorAnalyzer ;
@@ -43,23 +44,14 @@ final class ReadonlyPromotedPropertiesFixer extends AbstractFixer
4344 [\T_COALESCE_EQUAL , '??= ' ],
4445 [\T_CONCAT_EQUAL , '.= ' ],
4546 ];
46-
47- /** @var list<int> */
48- private array $ promotedPropertyVisibilityKinds ;
49-
50- public function __construct ()
51- {
52- $ this ->promotedPropertyVisibilityKinds = [
53- CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE ,
54- CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED ,
55- CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC ,
56- ];
57- if (\defined ('T_PUBLIC_SET ' )) {
58- $ this ->promotedPropertyVisibilityKinds [] = \T_PUBLIC_SET ;
59- $ this ->promotedPropertyVisibilityKinds [] = \T_PROTECTED_SET ;
60- $ this ->promotedPropertyVisibilityKinds [] = \T_PRIVATE_SET ;
61- }
62- }
47+ private const PROMOTED_PROPERTY_VISIBILITY_KINDS = [
48+ CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE ,
49+ CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED ,
50+ CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC ,
51+ FCT ::T_PUBLIC_SET ,
52+ FCT ::T_PROTECTED_SET ,
53+ FCT ::T_PRIVATE_SET ,
54+ ];
6355
6456 public function getDefinition (): FixerDefinitionInterface
6557 {
@@ -92,7 +84,7 @@ public function getPriority(): int
9284
9385 public function isCandidate (Tokens $ tokens ): bool
9486 {
95- return \defined ( ' T_READONLY ' ) && $ tokens ->isAnyTokenKindsFound ($ this -> promotedPropertyVisibilityKinds );
87+ return $ tokens ->isAnyTokenKindsFound (self :: PROMOTED_PROPERTY_VISIBILITY_KINDS );
9688 }
9789
9890 public function isRisky (): bool
@@ -126,7 +118,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
126118 \assert (\is_int ($ constructorOpenParenthesisIndex ));
127119 $ constructorCloseParenthesisIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ constructorOpenParenthesisIndex );
128120
129- $ this -> fixParameters (
121+ self :: fixParameters (
130122 $ tokens ,
131123 $ classOpenBraceIndex ,
132124 $ classCloseBraceIndex ,
@@ -146,7 +138,7 @@ private static function isClassReadonly(Tokens $tokens, int $index): bool
146138 return $ tokens [$ index ]->isGivenKind (\T_READONLY );
147139 }
148140
149- private function fixParameters (
141+ private static function fixParameters (
150142 Tokens $ tokens ,
151143 int $ classOpenBraceIndex ,
152144 int $ classCloseBraceIndex ,
@@ -158,7 +150,7 @@ private function fixParameters(
158150 continue ;
159151 }
160152
161- $ insertIndex = $ this -> getInsertIndex ($ tokens , $ index );
153+ $ insertIndex = self :: getInsertIndex ($ tokens , $ index );
162154 if ($ insertIndex === null ) {
163155 continue ;
164156 }
@@ -177,7 +169,7 @@ private function fixParameters(
177169 }
178170 }
179171
180- private function getInsertIndex (Tokens $ tokens , int $ index ): ?int
172+ private static function getInsertIndex (Tokens $ tokens , int $ index ): ?int
181173 {
182174 $ insertIndex = null ;
183175
@@ -189,7 +181,7 @@ private function getInsertIndex(Tokens $tokens, int $index): ?int
189181 if ($ tokens [$ index ]->isGivenKind (\T_READONLY )) {
190182 return null ;
191183 }
192- if ($ insertIndex === null && $ tokens [$ index ]->isGivenKind ($ this -> promotedPropertyVisibilityKinds )) {
184+ if ($ insertIndex === null && $ tokens [$ index ]->isGivenKind (self :: PROMOTED_PROPERTY_VISIBILITY_KINDS )) {
193185 $ insertIndex = $ index ;
194186 }
195187 }
0 commit comments