6
6
use PHPStan \Analyser \Scope ;
7
7
use PHPStan \Node \InClassMethodNode ;
8
8
use PHPStan \Reflection \ClassReflection ;
9
- use PHPStan \Reflection \ExtendedMethodReflection ;
10
9
use PHPStan \Reflection \ExtendedParameterReflection ;
11
10
use PHPStan \Reflection \ExtendedParametersAcceptor ;
12
- use PHPStan \Reflection \Php \PhpClassReflectionExtension ;
13
11
use PHPStan \Rules \IdentifierRuleError ;
14
12
use PHPStan \Rules \Rule ;
15
13
use PHPStan \Rules \RuleError ;
@@ -40,7 +38,7 @@ final class MethodSignatureRule implements Rule
40
38
{
41
39
42
40
public function __construct (
43
- private PhpClassReflectionExtension $ phpClassReflectionExtension ,
41
+ private ParentMethodHelper $ parentMethodHelper ,
44
42
private bool $ reportMaybes ,
45
43
private bool $ reportStatic ,
46
44
)
@@ -67,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array
67
65
}
68
66
$ errors = [];
69
67
$ declaringClass = $ method ->getDeclaringClass ();
70
- foreach ($ this ->collectParentMethods ($ methodName , $ method ->getDeclaringClass ()) as [$ parentMethod , $ parentMethodDeclaringClass ]) {
68
+ foreach ($ this ->parentMethodHelper -> collectParentMethods ($ methodName , $ method ->getDeclaringClass ()) as [$ parentMethod , $ parentMethodDeclaringClass ]) {
71
69
$ parentVariants = $ parentMethod ->getVariants ();
72
70
if (count ($ parentVariants ) !== 1 ) {
73
71
continue ;
@@ -141,57 +139,6 @@ public function processNode(Node $node, Scope $scope): array
141
139
return $ errors ;
142
140
}
143
141
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
-
195
142
/**
196
143
* @return array{TrinaryLogic, Type, Type}
197
144
*/
0 commit comments