Skip to content

Commit a7893a8

Browse files
committed
MissingTypehintCheck - do not report iterable template types
1 parent 2d1cac0 commit a7893a8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Rules/MissingTypehintCheck.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Reflection\ReflectionProvider;
66
use PHPStan\Type\Generic\GenericObjectType;
7+
use PHPStan\Type\Generic\TemplateType;
78
use PHPStan\Type\Generic\TemplateTypeHelper;
89
use PHPStan\Type\MixedType;
910
use PHPStan\Type\ObjectType;
@@ -57,6 +58,9 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array
5758

5859
$iterablesWithMissingValueTypehint = [];
5960
TypeTraverser::map($type, function (Type $type, callable $traverse) use (&$iterablesWithMissingValueTypehint): Type {
61+
if ($type instanceof TemplateType) {
62+
return $type;
63+
}
6064
if ($type->isIterable()->yes()) {
6165
$iterableValue = $type->getIterableValueType();
6266
if ($iterableValue instanceof MixedType && !$iterableValue->isExplicitMixed()) {

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

+14
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ public function acceptsCollection3(\DoctrineIntersectionTypeIsSupertypeOf\Collec
130130
}
131131

132132
}
133+
134+
class TraversableInTemplateBound
135+
{
136+
137+
/**
138+
* @template T of \Iterator
139+
* @param T $it
140+
*/
141+
public function doFoo($it)
142+
{
143+
144+
}
145+
146+
}

0 commit comments

Comments
 (0)