Skip to content

Commit a3fad5e

Browse files
committed
MissingTypehintCheck - do not report non-generic object types of generic class
1 parent a7893a8 commit a3fad5e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

phpstan-baseline.neon

-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ parameters:
135135
count: 1
136136
path: src/Rules/Registry.php
137137

138-
-
139-
message: "#^Method PHPStan\\\\Testing\\\\RuleTestCase\\:\\:getRule\\(\\) return type with generic interface PHPStan\\\\Rules\\\\Rule does not specify its types\\: TNodeType$#"
140-
count: 1
141-
path: src/Testing/RuleTestCase.php
142-
143138
-
144139
message: "#^Cannot call method getActiveTemplateTypeMap\\(\\) on PHPStan\\\\Reflection\\\\ClassReflection\\|null\\.$#"
145140
count: 2

src/Rules/MissingTypehintCheck.php

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public function getNonGenericObjectTypesWithGenericClass(Type $type): array
9999
if ($type instanceof GenericObjectType) {
100100
return $type;
101101
}
102+
if ($type instanceof TemplateType) {
103+
return $type;
104+
}
102105
if ($type instanceof ObjectType) {
103106
$classReflection = $type->getClassReflection();
104107
if ($classReflection === null) {

tests/PHPStan/Rules/Methods/data/missing-method-parameter-typehint.php

+14
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,17 @@ public function doFoo($it)
144144
}
145145

146146
}
147+
148+
class GenericClassInTemplateBound
149+
{
150+
151+
/**
152+
* @template T of GenericClass
153+
* @param T $obj
154+
*/
155+
public function doFoo($obj)
156+
{
157+
158+
}
159+
160+
}

0 commit comments

Comments
 (0)