From a3fad5eb6bd9801414a5cb6fa2084e074063bff4 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sat, 2 May 2020 22:14:47 +0200 Subject: [PATCH] MissingTypehintCheck - do not report non-generic object types of generic class --- phpstan-baseline.neon | 5 ----- src/Rules/MissingTypehintCheck.php | 3 +++ .../data/missing-method-parameter-typehint.php | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6561aa7c09..e8899bc132 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -135,11 +135,6 @@ parameters: count: 1 path: src/Rules/Registry.php - - - message: "#^Method PHPStan\\\\Testing\\\\RuleTestCase\\:\\:getRule\\(\\) return type with generic interface PHPStan\\\\Rules\\\\Rule does not specify its types\\: TNodeType$#" - count: 1 - path: src/Testing/RuleTestCase.php - - message: "#^Cannot call method getActiveTemplateTypeMap\\(\\) on PHPStan\\\\Reflection\\\\ClassReflection\\|null\\.$#" count: 2 diff --git a/src/Rules/MissingTypehintCheck.php b/src/Rules/MissingTypehintCheck.php index 837c37eeca..b42c86eda2 100644 --- a/src/Rules/MissingTypehintCheck.php +++ b/src/Rules/MissingTypehintCheck.php @@ -99,6 +99,9 @@ public function getNonGenericObjectTypesWithGenericClass(Type $type): array if ($type instanceof GenericObjectType) { return $type; } + if ($type instanceof TemplateType) { + return $type; + } if ($type instanceof ObjectType) { $classReflection = $type->getClassReflection(); if ($classReflection === null) { diff --git a/tests/PHPStan/Rules/Methods/data/missing-method-parameter-typehint.php b/tests/PHPStan/Rules/Methods/data/missing-method-parameter-typehint.php index b2f026c1b4..decbf3f65f 100644 --- a/tests/PHPStan/Rules/Methods/data/missing-method-parameter-typehint.php +++ b/tests/PHPStan/Rules/Methods/data/missing-method-parameter-typehint.php @@ -144,3 +144,17 @@ public function doFoo($it) } } + +class GenericClassInTemplateBound +{ + + /** + * @template T of GenericClass + * @param T $obj + */ + public function doFoo($obj) + { + + } + +}