|
4 | 4 |
|
5 | 5 | use PhpParser\Node\Stmt\ClassLike;
|
6 | 6 | use PHPStan\Analyser\NameScope;
|
| 7 | +use PHPStan\Internal\SprintfHelper; |
7 | 8 | use PHPStan\PhpDoc\TypeNodeResolver;
|
8 | 9 | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
9 | 10 | use PHPStan\Reflection\ClassReflection;
|
10 | 11 | use PHPStan\Reflection\ReflectionProvider;
|
11 | 12 | use PHPStan\Rules\ClassNameCheck;
|
12 | 13 | use PHPStan\Rules\ClassNameNodePair;
|
| 14 | +use PHPStan\Rules\Generics\GenericObjectTypeCheck; |
13 | 15 | use PHPStan\Rules\IdentifierRuleError;
|
14 | 16 | use PHPStan\Rules\MissingTypehintCheck;
|
15 | 17 | use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper;
|
@@ -39,6 +41,7 @@ public function __construct(
|
39 | 41 | private MissingTypehintCheck $missingTypehintCheck,
|
40 | 42 | private ClassNameCheck $classCheck,
|
41 | 43 | private UnresolvableTypeHelper $unresolvableTypeHelper,
|
| 44 | + private GenericObjectTypeCheck $genericObjectTypeCheck, |
42 | 45 | private bool $checkMissingTypehints,
|
43 | 46 | private bool $checkClassCaseSensitivity,
|
44 | 47 | private bool $absentTypeChecks,
|
@@ -256,6 +259,35 @@ public function check(ClassReflection $reflection, ClassLike $node): array
|
256 | 259 | ->identifier('typeAlias.unresolvableType')
|
257 | 260 | ->build();
|
258 | 261 | }
|
| 262 | + |
| 263 | + $escapedTypeAlias = SprintfHelper::escapeFormatString($aliasName); |
| 264 | + $errors = array_merge($errors, $this->genericObjectTypeCheck->check( |
| 265 | + $resolvedType, |
| 266 | + sprintf( |
| 267 | + 'Type alias %s contains generic type %%s but %%s %%s is not generic.', |
| 268 | + $escapedTypeAlias, |
| 269 | + ), |
| 270 | + sprintf( |
| 271 | + 'Generic type %%s in type alias %s does not specify all template types of %%s %%s: %%s', |
| 272 | + $escapedTypeAlias, |
| 273 | + ), |
| 274 | + sprintf( |
| 275 | + 'Generic type %%s in type alias %s specifies %%d template types, but %%s %%s supports only %%d: %%s', |
| 276 | + $escapedTypeAlias, |
| 277 | + ), |
| 278 | + sprintf( |
| 279 | + 'Type %%s in generic type %%s in type alias %s is not subtype of template type %%s of %%s %%s.', |
| 280 | + $escapedTypeAlias, |
| 281 | + ), |
| 282 | + sprintf( |
| 283 | + 'Call-site variance of %%s in generic type %%s in type alias %s is in conflict with %%s template type %%s of %%s %%s.', |
| 284 | + $escapedTypeAlias, |
| 285 | + ), |
| 286 | + sprintf( |
| 287 | + 'Call-site variance of %%s in generic type %%s in type alias %s is redundant, template type %%s of %%s %%s has the same variance.', |
| 288 | + $escapedTypeAlias, |
| 289 | + ), |
| 290 | + )); |
259 | 291 | }
|
260 | 292 |
|
261 | 293 | return $errors;
|
|
0 commit comments