@@ -85,38 +85,6 @@ public function __construct(\Rector\NodeManipulator\ClassInsertManipulator $clas
8585 $ this ->reflectionResolver = $ reflectionResolver ;
8686 $ this ->astResolver = $ astResolver ;
8787 }
88- private function resolveConstruct (Class_ $ class ) : ?ClassMethod
89- {
90- /** @var ClassMethod|null $constructorMethod */
91- $ constructorMethod = $ class ->getMethod (MethodName::CONSTRUCT );
92- // exists in current class
93- if ($ constructorMethod instanceof ClassMethod) {
94- return $ constructorMethod ;
95- }
96- // lookup parent, found first found (nearest parent constructor to follow)
97- $ classReflection = $ this ->reflectionResolver ->resolveClassReflection ($ class );
98- if (!$ classReflection instanceof ClassReflection) {
99- return null ;
100- }
101- $ ancestors = \array_filter ($ classReflection ->getAncestors (), static fn (ClassReflection $ ancestor ): bool => $ ancestor ->getName () !== $ classReflection ->getName ());
102- foreach ($ ancestors as $ ancestor ) {
103- if (!$ ancestor ->hasNativeMethod (MethodName::CONSTRUCT )) {
104- continue ;
105- }
106- $ parentClass = $ this ->astResolver ->resolveClassFromClassReflection ($ ancestor );
107- if (!$ parentClass instanceof ClassLike) {
108- continue ;
109- }
110- $ parentConstructorMethod = $ parentClass ->getMethod (MethodName::CONSTRUCT );
111- if (!$ parentConstructorMethod instanceof ClassMethod) {
112- continue ;
113- }
114- // reprint parent method node to avoid invalid tokens
115- $ this ->nodeFactory ->createReprintedNode ($ parentConstructorMethod );
116- return $ parentConstructorMethod ;
117- }
118- return null ;
119- }
12088 public function addConstructorDependency (Class_ $ class , PropertyMetadata $ propertyMetadata ) : void
12189 {
12290 // already has property as dependency? skip it
@@ -192,6 +160,38 @@ public function addStmtsToConstructorIfNotThereYet(Class_ $class, array $stmts)
192160 }
193161 $ classMethod ->stmts = \array_merge ($ stmts , (array ) $ classMethod ->stmts );
194162 }
163+ private function resolveConstruct (Class_ $ class ) : ?ClassMethod
164+ {
165+ /** @var ClassMethod|null $constructorMethod */
166+ $ constructorMethod = $ class ->getMethod (MethodName::CONSTRUCT );
167+ // exists in current class
168+ if ($ constructorMethod instanceof ClassMethod) {
169+ return $ constructorMethod ;
170+ }
171+ // lookup parent, found first found (nearest parent constructor to follow)
172+ $ classReflection = $ this ->reflectionResolver ->resolveClassReflection ($ class );
173+ if (!$ classReflection instanceof ClassReflection) {
174+ return null ;
175+ }
176+ $ ancestors = \array_filter ($ classReflection ->getAncestors (), static fn (ClassReflection $ ancestor ): bool => $ ancestor ->getName () !== $ classReflection ->getName ());
177+ foreach ($ ancestors as $ ancestor ) {
178+ if (!$ ancestor ->hasNativeMethod (MethodName::CONSTRUCT )) {
179+ continue ;
180+ }
181+ $ parentClass = $ this ->astResolver ->resolveClassFromClassReflection ($ ancestor );
182+ if (!$ parentClass instanceof ClassLike) {
183+ continue ;
184+ }
185+ $ parentConstructorMethod = $ parentClass ->getMethod (MethodName::CONSTRUCT );
186+ if (!$ parentConstructorMethod instanceof ClassMethod) {
187+ continue ;
188+ }
189+ // reprint parent method node to avoid invalid tokens
190+ $ this ->nodeFactory ->createReprintedNode ($ parentConstructorMethod );
191+ return $ parentConstructorMethod ;
192+ }
193+ return null ;
194+ }
195195 private function addPromotedProperty (Class_ $ class , PropertyMetadata $ propertyMetadata , ?ClassMethod $ constructClassMethod ) : void
196196 {
197197 $ param = $ this ->nodeFactory ->createPromotedPropertyParam ($ propertyMetadata );
0 commit comments