Skip to content

Commit 5b34cdb

Browse files
committed
[BE] Absent type checks
1 parent 84ab800 commit 5b34cdb

26 files changed

+52
-142
lines changed

changelog-2.0.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ Major new features 🚀
1010
* **Enhancements in Handling Parameters Passed by Reference**
1111
* [Learn more on phpstan.org](https://phpstan.org/blog/enhancements-in-handling-parameters-passed-by-reference)
1212
* [#2941](https://github.com/phpstan/phpstan-src/pull/2941), thanks @ljmaskey!
13+
* Added previously absent type checks (level 0)
14+
* Check existing classes in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/6838669976bf20232abde36ecdd52b1770fa50c9)
15+
* Check nonexistent classes in local type aliases (https://github.com/phpstan/phpstan-src/commit/2485b2e9c129e789ec3b2d7db81ca30f87c63911)
16+
* Check unresolvable types in local type aliases (https://github.com/phpstan/phpstan-src/commit/5f7d12b2fb2809525ab0e96eeae95093204ea4d3)
17+
* Check generics in local type aliases (https://github.com/phpstan/phpstan-src/commit/5a2d4416d94ab77a2a2e7e1bfaba4c5ed2a13c25)
18+
* Check existing classes in `@param-out` (https://github.com/phpstan/phpstan-src/commit/30c4b9e80f51af8b5f166ba3aae93d8409c9c0ea), #10260
19+
* Check existing classes in `@param-closure-this` (https://github.com/phpstan/phpstan-src/commit/2fa539a39e06bcc3155b109fd8d246703ceb176d), #10933
20+
* Added previously absent type checks (level 2)
21+
* Check `@mixin` PHPDoc tag above traits (https://github.com/phpstan/phpstan-src/commit/0d0de946900adf4eb3c799b1b547567536e23147)
22+
* Check `@extends`, `@implements`, `@use` for unresolvable types (https://github.com/phpstan/phpstan-src/commit/2bb528233edb75312614166e282776f279cf2018), #11552
23+
* Check types in `@method` tags (https://github.com/phpstan/phpstan-src/commit/5b7e474680eaf33874b7ed6a227677adcbed9ca5)
24+
* Check generics `@method` `@template` tags above traits (https://github.com/phpstan/phpstan-src/commit/aadbf62d3ae4517fc7a212b07130bedcef8d13ac)
25+
* Check types in `@property` tags (https://github.com/phpstan/phpstan-src/commit/55ea2ae516df22a071ab873fdd6f748a3af0520e), #10752, #9356
26+
* Added previously absent type checks (level 6)
27+
* Check missing types in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/892b319f25f04bc1b55c3d0063b607909612fe6d)
28+
* Check missing types in local type aliases (https://github.com/phpstan/phpstan-src/commit/ce7ffaf02d624a7fb9d38f8e5dffc9739f1233fc)
29+
* Check missing types in `@mixin` (https://github.com/phpstan/phpstan-src/commit/3175c81f26fd5bcb4a161b24e774921870ed2533)
1330

1431
Bleeding edge (TODO move to other sections)
1532
=====================
@@ -82,25 +99,10 @@ Bleeding edge (TODO move to other sections)
8299
* BetterNoopRule - take advantage of impure points (https://github.com/phpstan/phpstan-src/commit/a6470521b65d7424f552633c1f3827704c6262c3), #10389
83100
* CallToConstructorStatementWithoutSideEffectsRule - report class with no constructor (https://github.com/phpstan/phpstan-src/commit/b116d25a6e4ba6c09f59af6569d9e6f6fd20aff4)
84101
* Check if required file exists ([#3294](https://github.com/phpstan/phpstan-src/pull/3294)), #3397, thanks @Bellangelo!
85-
* Check generics `@method` `@template` tags above traits (https://github.com/phpstan/phpstan-src/commit/aadbf62d3ae4517fc7a212b07130bedcef8d13ac)
86-
* Check `@mixin` PHPDoc tag above traits (https://github.com/phpstan/phpstan-src/commit/0d0de946900adf4eb3c799b1b547567536e23147)
87102
* More precise types for bcmath function parameters ([#2217](https://github.com/phpstan/phpstan-src/pull/2217)), thanks @Warxcell!
88103
* Enforce `@no-named-arguments` (https://github.com/phpstan/phpstan-src/commit/74ba8c23696948f2647d880df72f375346f41010), #5968
89104
* Check too wide private property type (https://github.com/phpstan/phpstan-src/commit/7453f4f75fae3d635063589467842aae29d88b54)
90-
* Check existing classes in `@param-out` (https://github.com/phpstan/phpstan-src/commit/30c4b9e80f51af8b5f166ba3aae93d8409c9c0ea), #10260
91-
* Check existing classes in `@param-closure-this` (https://github.com/phpstan/phpstan-src/commit/2fa539a39e06bcc3155b109fd8d246703ceb176d), #10933
92-
* Check invalid `@param-closure-this` (https://github.com/phpstan/phpstan-src/commit/95c0a5806c65c975201b9d3a464873f75a04c8b8), #10932
93105
* Check `@param-immediately-invoked-callable` and `@param-later-invoked-callable` (https://github.com/phpstan/phpstan-src/commit/580a6add422f4e34191df9e7a77ba1655e914bda), #10932
94-
* Check existing classes in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/6838669976bf20232abde36ecdd52b1770fa50c9)
95-
* Check missing types in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/892b319f25f04bc1b55c3d0063b607909612fe6d)
96-
* Check missing types in local type aliases (https://github.com/phpstan/phpstan-src/commit/ce7ffaf02d624a7fb9d38f8e5dffc9739f1233fc)
97-
* Check nonexistent classes in local type aliases (https://github.com/phpstan/phpstan-src/commit/2485b2e9c129e789ec3b2d7db81ca30f87c63911)
98-
* Check unresolvable types in local type aliases (https://github.com/phpstan/phpstan-src/commit/5f7d12b2fb2809525ab0e96eeae95093204ea4d3)
99-
* Check generics in local type aliases (https://github.com/phpstan/phpstan-src/commit/5a2d4416d94ab77a2a2e7e1bfaba4c5ed2a13c25)
100-
* Check missing types in `@mixin` (https://github.com/phpstan/phpstan-src/commit/3175c81f26fd5bcb4a161b24e774921870ed2533)
101-
* Check types in `@property` tags (https://github.com/phpstan/phpstan-src/commit/55ea2ae516df22a071ab873fdd6f748a3af0520e), #10752, #9356
102-
* Check types in `@method` tags (https://github.com/phpstan/phpstan-src/commit/5b7e474680eaf33874b7ed6a227677adcbed9ca5)
103-
* Check `@extends`, `@implements`, `@use` for unresolvable types (https://github.com/phpstan/phpstan-src/commit/2bb528233edb75312614166e282776f279cf2018), #11552
104106
* RegularExpressionPatternRule: validate preg_quote'd patterns ([#3270](https://github.com/phpstan/phpstan-src/pull/3270)), thanks @staabm!
105107
* Report useless return values of function calls like `var_export` without `$return=true` ([#3225](https://github.com/phpstan/phpstan-src/pull/3225)), #11320, thanks @staabm!
106108
* Check mixed in binary operator ([#3231](https://github.com/phpstan/phpstan-src/pull/3231)), #7538, #10440, thanks @schlndh!

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ parameters:
4343
printfArrayParameters: true
4444
validatePregQuote: true
4545
tooWidePropertyType: true
46-
absentTypeChecks: true
4746
requireFileExists: true

conf/config.level0.neon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ conditionalTags:
3232
phpstan.rules.rule: %featureToggles.validatePregQuote%
3333
PHPStan\Rules\Keywords\RequireFileExistsRule:
3434
phpstan.rules.rule: %featureToggles.requireFileExists%
35-
PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule:
36-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
3735

3836
rules:
3937
- PHPStan\Rules\Api\ApiInstantiationRule
@@ -63,6 +61,7 @@ rules:
6361
- PHPStan\Rules\Classes\InstantiationCallableRule
6462
- PHPStan\Rules\Classes\InvalidPromotedPropertiesRule
6563
- PHPStan\Rules\Classes\LocalTypeAliasesRule
64+
- PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule
6665
- PHPStan\Rules\Classes\LocalTypeTraitAliasesRule
6766
- PHPStan\Rules\Classes\NewStaticRule
6867
- PHPStan\Rules\Classes\NonClassAttributeClassRule
@@ -150,9 +149,6 @@ services:
150149
arguments:
151150
checkClassCaseSensitivity: %checkClassCaseSensitivity%
152151

153-
-
154-
class: PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule
155-
156152
-
157153
class: PHPStan\Rules\Exceptions\CaughtExceptionExistenceRule
158154
tags:

conf/config.level2.neon

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ rules:
1212
- PHPStan\Rules\Cast\InvalidPartOfEncapsedStringRule
1313
- PHPStan\Rules\Cast\PrintRule
1414
- PHPStan\Rules\Classes\AccessPrivateConstantThroughStaticRule
15+
- PHPStan\Rules\Classes\MethodTagRule
16+
- PHPStan\Rules\Classes\MethodTagTraitRule
17+
- PHPStan\Rules\Classes\MethodTagTraitUseRule
18+
- PHPStan\Rules\Classes\PropertyTagRule
19+
- PHPStan\Rules\Classes\PropertyTagTraitRule
20+
- PHPStan\Rules\Classes\PropertyTagTraitUseRule
21+
- PHPStan\Rules\Classes\MixinTraitRule
22+
- PHPStan\Rules\Classes\MixinTraitUseRule
1523
- PHPStan\Rules\Comparison\UsageOfVoidMatchExpressionRule
1624
- PHPStan\Rules\Constants\ValueAssignedToClassConstantRule
1725
- PHPStan\Rules\Functions\IncompatibleDefaultParameterTypeRule
@@ -25,6 +33,7 @@ rules:
2533
- PHPStan\Rules\Generics\InterfaceTemplateTypeRule
2634
- PHPStan\Rules\Generics\MethodTemplateTypeRule
2735
- PHPStan\Rules\Generics\MethodTagTemplateTypeRule
36+
- PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule
2837
- PHPStan\Rules\Generics\MethodSignatureVarianceRule
2938
- PHPStan\Rules\Generics\TraitTemplateTypeRule
3039
- PHPStan\Rules\Generics\UsedTraitsRule
@@ -49,28 +58,10 @@ rules:
4958
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionTraitRule
5059

5160
conditionalTags:
52-
PHPStan\Rules\Classes\MethodTagRule:
53-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
54-
PHPStan\Rules\Classes\MethodTagTraitRule:
55-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
56-
PHPStan\Rules\Classes\MethodTagTraitUseRule:
57-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
58-
PHPStan\Rules\Classes\MixinTraitRule:
59-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
60-
PHPStan\Rules\Classes\MixinTraitUseRule:
61-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
62-
PHPStan\Rules\Classes\PropertyTagRule:
63-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
64-
PHPStan\Rules\Classes\PropertyTagTraitRule:
65-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
66-
PHPStan\Rules\Classes\PropertyTagTraitUseRule:
67-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
6861
PHPStan\Rules\Functions\IncompatibleArrowFunctionDefaultParameterTypeRule:
6962
phpstan.rules.rule: %featureToggles.closureDefaultParameterTypeRule%
7063
PHPStan\Rules\Functions\IncompatibleClosureDefaultParameterTypeRule:
7164
phpstan.rules.rule: %featureToggles.closureDefaultParameterTypeRule%
72-
PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule:
73-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
7465
PHPStan\Rules\Methods\IllegalConstructorMethodCallRule:
7566
phpstan.rules.rule: %featureToggles.illegalConstructorMethodCall%
7667
PHPStan\Rules\Methods\IllegalConstructorStaticCallRule:
@@ -90,30 +81,6 @@ services:
9081
tags:
9182
- phpstan.rules.rule
9283

93-
-
94-
class: PHPStan\Rules\Classes\MixinTraitRule
95-
96-
-
97-
class: PHPStan\Rules\Classes\MixinTraitUseRule
98-
99-
-
100-
class: PHPStan\Rules\Classes\MethodTagRule
101-
102-
-
103-
class: PHPStan\Rules\Classes\MethodTagTraitRule
104-
105-
-
106-
class: PHPStan\Rules\Classes\MethodTagTraitUseRule
107-
108-
-
109-
class: PHPStan\Rules\Classes\PropertyTagRule
110-
111-
-
112-
class: PHPStan\Rules\Classes\PropertyTagTraitRule
113-
114-
-
115-
class: PHPStan\Rules\Classes\PropertyTagTraitUseRule
116-
11784
-
11885
class: PHPStan\Rules\PhpDoc\RequireExtendsCheck
11986
arguments:
@@ -137,8 +104,6 @@ services:
137104
tags:
138105
- phpstan.rules.rule
139106

140-
-
141-
class: PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule
142107
-
143108
class: PHPStan\Rules\Methods\IllegalConstructorMethodCallRule
144109
-

conf/config.level6.neon

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,5 @@ rules:
1313
- PHPStan\Rules\Functions\MissingFunctionReturnTypehintRule
1414
- PHPStan\Rules\Methods\MissingMethodParameterTypehintRule
1515
- PHPStan\Rules\Methods\MissingMethodReturnTypehintRule
16+
- PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule
1617
- PHPStan\Rules\Properties\MissingPropertyTypehintRule
17-
18-
conditionalTags:
19-
PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule:
20-
phpstan.rules.rule: %featureToggles.absentTypeChecks%
21-
22-
services:
23-
-
24-
class: PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule

conf/config.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ parameters:
8181
requireFileExists: false
8282
narrowPregMatches: true
8383
tooWidePropertyType: false
84-
absentTypeChecks: false
8584
fileExtensions:
8685
- php
8786
checkAdvancedIsset: false
@@ -906,7 +905,6 @@ services:
906905
globalTypeAliases: %typeAliases%
907906
checkMissingTypehints: %checkMissingTypehints%
908907
checkClassCaseSensitivity: %checkClassCaseSensitivity%
909-
absentTypeChecks: %featureToggles.absentTypeChecks%
910908

911909
-
912910
class: PHPStan\Rules\Classes\MethodTagCheck
@@ -918,7 +916,6 @@ services:
918916
class: PHPStan\Rules\Classes\MixinCheck
919917
arguments:
920918
checkClassCaseSensitivity: %checkClassCaseSensitivity%
921-
absentTypeChecks: %featureToggles.absentTypeChecks%
922919
checkMissingTypehints: %checkMissingTypehints%
923920

924921
-
@@ -984,7 +981,6 @@ services:
984981
arguments:
985982
checkClassCaseSensitivity: %checkClassCaseSensitivity%
986983
checkThisOnly: %checkThisOnly%
987-
absentTypeChecks: %featureToggles.absentTypeChecks%
988984

989985
-
990986
class: PHPStan\Rules\FunctionReturnTypeCheck
@@ -999,7 +995,6 @@ services:
999995
arguments:
1000996
checkGenericClassInNonGenericObjectType: %checkGenericClassInNonGenericObjectType%
1001997
skipCheckGenericClasses: %featureToggles.skipCheckGenericClasses%
1002-
absentTypeChecks: %featureToggles.absentTypeChecks%
1003998

1004999
-
10051000
class: PHPStan\Rules\Generics\GenericObjectTypeCheck

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ parametersSchema:
7474
validatePregQuote: bool()
7575
narrowPregMatches: bool()
7676
tooWidePropertyType: bool()
77-
absentTypeChecks: bool()
7877
requireFileExists: bool()
7978
])
8079
fileExtensions: listOf(string())

src/PhpDoc/StubValidator.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ private function getRuleRegistry(Container $container): RuleRegistry
186186
$genericCallableRuleHelper = $container->getByType(GenericCallableRuleHelper::class);
187187
$methodTagTemplateTypeCheck = $container->getByType(MethodTagTemplateTypeCheck::class);
188188
$mixinCheck = $container->getByType(MixinCheck::class);
189+
$methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
190+
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
189191

190192
$rules = [
191193
// level 0
@@ -200,6 +202,7 @@ private function getRuleRegistry(Container $container): RuleRegistry
200202
new DuplicateDeclarationRule(),
201203
new LocalTypeAliasesRule($localTypeAliasesCheck),
202204
new LocalTypeTraitAliasesRule($localTypeAliasesCheck, $reflectionProvider),
205+
new LocalTypeTraitUseAliasesRule($localTypeAliasesCheck),
203206

204207
// level 2
205208
new ClassAncestorsRule($genericAncestorsCheck, $crossCheckInterfacesHelper),
@@ -226,13 +229,24 @@ private function getRuleRegistry(Container $container): RuleRegistry
226229
$container->getByType(PhpDocParser::class),
227230
),
228231
new InvalidThrowsPhpDocValueRule($fileTypeMapper),
232+
new MixinTraitRule($mixinCheck, $reflectionProvider),
233+
new MixinRule($mixinCheck),
234+
new MixinTraitUseRule($mixinCheck),
235+
new MethodTagRule($methodTagCheck),
236+
new MethodTagTraitRule($methodTagCheck, $reflectionProvider),
237+
new MethodTagTraitUseRule($methodTagCheck),
238+
new MethodTagTemplateTypeTraitRule($methodTagTemplateTypeCheck, $reflectionProvider),
239+
new PropertyTagRule($propertyTagCheck),
240+
new PropertyTagTraitRule($propertyTagCheck, $reflectionProvider),
241+
new PropertyTagTraitUseRule($propertyTagCheck),
229242

230243
// level 6
231244
new MissingFunctionParameterTypehintRule($missingTypehintCheck),
232245
new MissingFunctionReturnTypehintRule($missingTypehintCheck),
233246
new MissingMethodParameterTypehintRule($missingTypehintCheck),
234247
new MissingMethodReturnTypehintRule($missingTypehintCheck),
235248
new MissingPropertyTypehintRule($missingTypehintCheck),
249+
new MissingMethodSelfOutTypeRule($missingTypehintCheck),
236250
];
237251

238252
if ($this->duplicateStubs) {
@@ -242,25 +256,6 @@ private function getRuleRegistry(Container $container): RuleRegistry
242256
$rules[] = new DuplicateFunctionDeclarationRule($reflector, $relativePathHelper);
243257
}
244258

245-
if ((bool) $container->getParameter('featureToggles')['absentTypeChecks']) {
246-
$rules[] = new MissingMethodSelfOutTypeRule($missingTypehintCheck);
247-
248-
$methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
249-
$rules[] = new MethodTagRule($methodTagCheck);
250-
$rules[] = new MethodTagTraitRule($methodTagCheck, $reflectionProvider);
251-
$rules[] = new MethodTagTraitUseRule($methodTagCheck);
252-
253-
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
254-
$rules[] = new PropertyTagRule($propertyTagCheck);
255-
$rules[] = new PropertyTagTraitRule($propertyTagCheck, $reflectionProvider);
256-
$rules[] = new PropertyTagTraitUseRule($propertyTagCheck);
257-
$rules[] = new MixinRule($mixinCheck);
258-
$rules[] = new MixinTraitRule($mixinCheck, $reflectionProvider);
259-
$rules[] = new MixinTraitUseRule($mixinCheck);
260-
$rules[] = new LocalTypeTraitUseAliasesRule($localTypeAliasesCheck);
261-
$rules[] = new MethodTagTemplateTypeTraitRule($methodTagTemplateTypeCheck, $reflectionProvider);
262-
}
263-
264259
return new DirectRuleRegistry($rules);
265260
}
266261

src/Rules/Classes/LocalTypeAliasesCheck.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function __construct(
4444
private GenericObjectTypeCheck $genericObjectTypeCheck,
4545
private bool $checkMissingTypehints,
4646
private bool $checkClassCaseSensitivity,
47-
private bool $absentTypeChecks,
4847
)
4948
{
5049
}
@@ -182,10 +181,6 @@ public function checkInTraitDefinitionContext(ClassReflection $reflection): arra
182181
continue;
183182
}
184183

185-
if (!$this->absentTypeChecks) {
186-
continue;
187-
}
188-
189184
if (!$this->checkMissingTypehints) {
190185
continue;
191186
}

src/Rules/Classes/MixinCheck.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(
2727
private MissingTypehintCheck $missingTypehintCheck,
2828
private UnresolvableTypeHelper $unresolvableTypeHelper,
2929
private bool $checkClassCaseSensitivity,
30-
private bool $absentTypeChecks,
3130
private bool $checkMissingTypehints,
3231
)
3332
{
@@ -65,10 +64,6 @@ public function checkInTraitDefinitionContext(ClassReflection $classReflection):
6564
continue;
6665
}
6766

68-
if (!$this->absentTypeChecks) {
69-
continue;
70-
}
71-
7267
if (!$this->checkMissingTypehints) {
7368
continue;
7469
}

0 commit comments

Comments
 (0)