66use PHPStan \Analyser \Scope ;
77use PHPStan \Node \InClassMethodNode ;
88use PHPStan \Reflection \ClassReflection ;
9- use PHPStan \Reflection \ExtendedMethodReflection ;
109use PHPStan \Reflection \ExtendedParameterReflection ;
1110use PHPStan \Reflection \ExtendedParametersAcceptor ;
12- use PHPStan \Reflection \Php \PhpClassReflectionExtension ;
1311use PHPStan \Rules \IdentifierRuleError ;
1412use PHPStan \Rules \Rule ;
1513use PHPStan \Rules \RuleError ;
@@ -40,7 +38,7 @@ final class MethodSignatureRule implements Rule
4038{
4139
4240 public function __construct (
43- private PhpClassReflectionExtension $ phpClassReflectionExtension ,
41+ private ParentMethodHelper $ parentMethodHelper ,
4442 private bool $ reportMaybes ,
4543 private bool $ reportStatic ,
4644 )
@@ -67,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array
6765 }
6866 $ errors = [];
6967 $ declaringClass = $ method ->getDeclaringClass ();
70- foreach ($ this ->collectParentMethods ($ methodName , $ method ->getDeclaringClass ()) as [$ parentMethod , $ parentMethodDeclaringClass ]) {
68+ foreach ($ this ->parentMethodHelper -> collectParentMethods ($ methodName , $ method ->getDeclaringClass ()) as [$ parentMethod , $ parentMethodDeclaringClass ]) {
7169 $ parentVariants = $ parentMethod ->getVariants ();
7270 if (count ($ parentVariants ) !== 1 ) {
7371 continue ;
@@ -141,57 +139,6 @@ public function processNode(Node $node, Scope $scope): array
141139 return $ errors ;
142140 }
143141
144- /**
145- * @return list<array{ExtendedMethodReflection, ClassReflection}>
146- */
147- private function collectParentMethods (string $ methodName , ClassReflection $ class ): array
148- {
149- $ parentMethods = [];
150-
151- $ parentClass = $ class ->getParentClass ();
152- if ($ parentClass !== null && $ parentClass ->hasNativeMethod ($ methodName )) {
153- $ parentMethod = $ parentClass ->getNativeMethod ($ methodName );
154- if (!$ parentMethod ->isPrivate ()) {
155- $ parentMethods [] = [$ parentMethod , $ parentMethod ->getDeclaringClass ()];
156- }
157- }
158-
159- foreach ($ class ->getInterfaces () as $ interface ) {
160- if (!$ interface ->hasNativeMethod ($ methodName )) {
161- continue ;
162- }
163-
164- $ method = $ interface ->getNativeMethod ($ methodName );
165- $ parentMethods [] = [$ method , $ method ->getDeclaringClass ()];
166- }
167-
168- foreach ($ class ->getTraits (true ) as $ trait ) {
169- $ nativeTraitReflection = $ trait ->getNativeReflection ();
170- if (!$ nativeTraitReflection ->hasMethod ($ methodName )) {
171- continue ;
172- }
173-
174- $ methodReflection = $ nativeTraitReflection ->getMethod ($ methodName );
175- $ isAbstract = $ methodReflection ->isAbstract ();
176- if (!$ isAbstract ) {
177- continue ;
178- }
179-
180- $ declaringTrait = $ trait ->getNativeMethod ($ methodName )->getDeclaringClass ();
181- $ parentMethods [] = [
182- $ this ->phpClassReflectionExtension ->createUserlandMethodReflection (
183- $ trait ,
184- $ class ,
185- $ methodReflection ,
186- $ declaringTrait ->getName (),
187- ),
188- $ declaringTrait ,
189- ];
190- }
191-
192- return $ parentMethods ;
193- }
194-
195142 /**
196143 * @return array{TrinaryLogic, Type, Type}
197144 */
0 commit comments