Skip to content

Commit c98d0a4

Browse files
committed
Bleeding edge - validate overriding methods in stubs
1 parent 3c3ea2f commit c98d0a4

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

conf/bleedingEdge.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ parameters:
2121
apiRules: true
2222
deepInspectTypes: true
2323
neverInGenericReturnType: true
24+
validateOverridingMethodsInStubs: true
2425
stubFiles:
2526
- ../stubs/arrayFunctions.stub

conf/config.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ parameters:
4444
apiRules: false
4545
deepInspectTypes: false
4646
neverInGenericReturnType: false
47+
validateOverridingMethodsInStubs: false
4748
fileExtensions:
4849
- php
4950
checkAlwaysTrueCheckTypeFunctionCall: false
@@ -215,7 +216,8 @@ parametersSchema:
215216
preciseExceptionTracking: bool(),
216217
apiRules: bool(),
217218
deepInspectTypes: bool(),
218-
neverInGenericReturnType: bool()
219+
neverInGenericReturnType: bool(),
220+
validateOverridingMethodsInStubs: bool()
219221
])
220222
fileExtensions: listOf(string())
221223
checkAlwaysTrueCheckTypeFunctionCall: bool()
@@ -418,6 +420,8 @@ services:
418420

419421
-
420422
class: PHPStan\PhpDoc\StubValidator
423+
arguments:
424+
validateOverridingMethods: %featureToggles.validateOverridingMethodsInStubs%
421425

422426
-
423427
class: PHPStan\Analyser\Analyser

src/PhpDoc/StubValidator.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Broker\Broker;
99
use PHPStan\DependencyInjection\Container;
1010
use PHPStan\DependencyInjection\DerivativeContainerFactory;
11+
use PHPStan\Php\PhpVersion;
1112
use PHPStan\PhpDocParser\Lexer\Lexer;
1213
use PHPStan\PhpDocParser\Parser\PhpDocParser;
1314
use PHPStan\Reflection\ReflectionProvider;
@@ -33,8 +34,10 @@
3334
use PHPStan\Rules\Generics\TraitTemplateTypeRule;
3435
use PHPStan\Rules\Generics\VarianceCheck;
3536
use PHPStan\Rules\Methods\ExistingClassesInTypehintsRule;
37+
use PHPStan\Rules\Methods\MethodSignatureRule;
3638
use PHPStan\Rules\Methods\MissingMethodParameterTypehintRule;
3739
use PHPStan\Rules\Methods\MissingMethodReturnTypehintRule;
40+
use PHPStan\Rules\Methods\OverridingMethodRule;
3841
use PHPStan\Rules\MissingTypehintCheck;
3942
use PHPStan\Rules\PhpDoc\IncompatiblePhpDocTypeRule;
4043
use PHPStan\Rules\PhpDoc\IncompatiblePropertyPhpDocTypeRule;
@@ -52,11 +55,15 @@ class StubValidator
5255

5356
private \PHPStan\DependencyInjection\DerivativeContainerFactory $derivativeContainerFactory;
5457

58+
private bool $validateOverridingMethods;
59+
5560
public function __construct(
56-
DerivativeContainerFactory $derivativeContainerFactory
61+
DerivativeContainerFactory $derivativeContainerFactory,
62+
bool $validateOverridingMethods
5763
)
5864
{
5965
$this->derivativeContainerFactory = $derivativeContainerFactory;
66+
$this->validateOverridingMethods = $validateOverridingMethods;
6067
}
6168

6269
/**
@@ -127,7 +134,7 @@ private function getRuleRegistry(Container $container): Registry
127134
$missingTypehintCheck = $container->getByType(MissingTypehintCheck::class);
128135
$unresolvableTypeHelper = $container->getByType(UnresolvableTypeHelper::class);
129136

130-
return new Registry([
137+
$rules = [
131138
// level 0
132139
new ExistingClassesInClassImplementsRule($classCaseSensitivityCheck, $reflectionProvider),
133140
new ExistingClassesInInterfaceExtendsRule($classCaseSensitivityCheck, $reflectionProvider),
@@ -165,7 +172,17 @@ private function getRuleRegistry(Container $container): Registry
165172
new MissingMethodParameterTypehintRule($missingTypehintCheck),
166173
new MissingMethodReturnTypehintRule($missingTypehintCheck),
167174
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);
169186
}
170187

171188
}

0 commit comments

Comments
 (0)