8
8
use PHPStan \Broker \Broker ;
9
9
use PHPStan \DependencyInjection \Container ;
10
10
use PHPStan \DependencyInjection \DerivativeContainerFactory ;
11
+ use PHPStan \Php \PhpVersion ;
11
12
use PHPStan \PhpDocParser \Lexer \Lexer ;
12
13
use PHPStan \PhpDocParser \Parser \PhpDocParser ;
13
14
use PHPStan \Reflection \ReflectionProvider ;
33
34
use PHPStan \Rules \Generics \TraitTemplateTypeRule ;
34
35
use PHPStan \Rules \Generics \VarianceCheck ;
35
36
use PHPStan \Rules \Methods \ExistingClassesInTypehintsRule ;
37
+ use PHPStan \Rules \Methods \MethodSignatureRule ;
36
38
use PHPStan \Rules \Methods \MissingMethodParameterTypehintRule ;
37
39
use PHPStan \Rules \Methods \MissingMethodReturnTypehintRule ;
40
+ use PHPStan \Rules \Methods \OverridingMethodRule ;
38
41
use PHPStan \Rules \MissingTypehintCheck ;
39
42
use PHPStan \Rules \PhpDoc \IncompatiblePhpDocTypeRule ;
40
43
use PHPStan \Rules \PhpDoc \IncompatiblePropertyPhpDocTypeRule ;
@@ -52,11 +55,15 @@ class StubValidator
52
55
53
56
private \PHPStan \DependencyInjection \DerivativeContainerFactory $ derivativeContainerFactory ;
54
57
58
+ private bool $ validateOverridingMethods ;
59
+
55
60
public function __construct (
56
- DerivativeContainerFactory $ derivativeContainerFactory
61
+ DerivativeContainerFactory $ derivativeContainerFactory ,
62
+ bool $ validateOverridingMethods
57
63
)
58
64
{
59
65
$ this ->derivativeContainerFactory = $ derivativeContainerFactory ;
66
+ $ this ->validateOverridingMethods = $ validateOverridingMethods ;
60
67
}
61
68
62
69
/**
@@ -127,7 +134,7 @@ private function getRuleRegistry(Container $container): Registry
127
134
$ missingTypehintCheck = $ container ->getByType (MissingTypehintCheck::class);
128
135
$ unresolvableTypeHelper = $ container ->getByType (UnresolvableTypeHelper::class);
129
136
130
- return new Registry ( [
137
+ $ rules = [
131
138
// level 0
132
139
new ExistingClassesInClassImplementsRule ($ classCaseSensitivityCheck , $ reflectionProvider ),
133
140
new ExistingClassesInInterfaceExtendsRule ($ classCaseSensitivityCheck , $ reflectionProvider ),
@@ -165,7 +172,17 @@ private function getRuleRegistry(Container $container): Registry
165
172
new MissingMethodParameterTypehintRule ($ missingTypehintCheck ),
166
173
new MissingMethodReturnTypehintRule ($ missingTypehintCheck ),
167
174
new MissingPropertyTypehintRule ($ missingTypehintCheck ),
168
- ]);
175
+ ];
176
+
177
+ if ($ this ->validateOverridingMethods ) {
178
+ $ rules [] = new OverridingMethodRule (
179
+ $ container ->getByType (PhpVersion::class),
180
+ new MethodSignatureRule (true , true ),
181
+ true
182
+ );
183
+ }
184
+
185
+ return new Registry ($ rules );
169
186
}
170
187
171
188
}
0 commit comments