@@ -83,11 +83,21 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
8383 continue ;
8484 }
8585
86- $ openParenthesis = $ tokens ->getNextTokenOfKind ($ constructorAnalysis ->getConstructorIndex (), ['( ' ]);
87- \assert (\is_int ($ openParenthesis ));
88- $ closeParenthesis = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ openParenthesis );
89-
90- $ this ->fixParameters ($ tokens , $ openParenthesis , $ closeParenthesis );
86+ $ classOpenBraceIndex = $ tokens ->getNextTokenOfKind ($ index , ['{ ' ]);
87+ \assert (\is_int ($ classOpenBraceIndex ));
88+ $ classCloseBraceIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_CURLY_BRACE , $ classOpenBraceIndex );
89+
90+ $ constructorOpenParenthesisIndex = $ tokens ->getNextTokenOfKind ($ constructorAnalysis ->getConstructorIndex (), ['( ' ]);
91+ \assert (\is_int ($ constructorOpenParenthesisIndex ));
92+ $ constructorCloseParenthesisIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ constructorOpenParenthesisIndex );
93+
94+ $ this ->fixParameters (
95+ $ tokens ,
96+ $ classOpenBraceIndex ,
97+ $ classCloseBraceIndex ,
98+ $ constructorOpenParenthesisIndex ,
99+ $ constructorCloseParenthesisIndex ,
100+ );
91101 }
92102 }
93103
@@ -101,9 +111,14 @@ private function isClassReadonly(Tokens $tokens, int $index): bool
101111 return $ tokens [$ index ]->isGivenKind (\T_READONLY );
102112 }
103113
104- private function fixParameters (Tokens $ tokens , int $ openParenthesis , int $ closeParenthesis ): void
105- {
106- for ($ index = $ closeParenthesis ; $ index > $ openParenthesis ; $ index --) {
114+ private function fixParameters (
115+ Tokens $ tokens ,
116+ int $ classOpenBraceIndex ,
117+ int $ classCloseBraceIndex ,
118+ int $ constructorOpenParenthesisIndex ,
119+ int $ constructorCloseParenthesisIndex
120+ ): void {
121+ for ($ index = $ constructorCloseParenthesisIndex ; $ index > $ constructorOpenParenthesisIndex ; $ index --) {
107122 if (
108123 !$ tokens [$ index ]->isGivenKind ([
109124 CT ::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE ,
@@ -124,6 +139,22 @@ private function fixParameters(Tokens $tokens, int $openParenthesis, int $closeP
124139 continue ;
125140 }
126141
142+ $ propertyIndex = $ tokens ->getNextTokenOfKind ($ index , [[\T_VARIABLE ]]);
143+ \assert (\is_int ($ propertyIndex ));
144+
145+ $ propertyAssignment = $ tokens ->findSequence (
146+ [
147+ [\T_VARIABLE , '$this ' ],
148+ [\T_OBJECT_OPERATOR ],
149+ [\T_STRING , \substr ($ tokens [$ propertyIndex ]->getContent (), 1 )],
150+ ],
151+ $ classOpenBraceIndex ,
152+ $ classCloseBraceIndex ,
153+ );
154+ if ($ propertyAssignment !== null ) {
155+ continue ;
156+ }
157+
127158 $ tokens ->insertAt (
128159 $ index + 1 ,
129160 [
0 commit comments