Skip to content

Commit

Permalink
MissingTypehintCheck - do not report iterable template types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 2, 2020
1 parent 2d1cac0 commit a7893a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Rules/MissingTypehintCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -57,6 +58,9 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array

$iterablesWithMissingValueTypehint = [];
TypeTraverser::map($type, function (Type $type, callable $traverse) use (&$iterablesWithMissingValueTypehint): Type {
if ($type instanceof TemplateType) {
return $type;
}
if ($type->isIterable()->yes()) {
$iterableValue = $type->getIterableValueType();
if ($iterableValue instanceof MixedType && !$iterableValue->isExplicitMixed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,17 @@ public function acceptsCollection3(\DoctrineIntersectionTypeIsSupertypeOf\Collec
}

}

class TraversableInTemplateBound
{

/**
* @template T of \Iterator
* @param T $it
*/
public function doFoo($it)
{

}

}

0 comments on commit a7893a8

Please sign in to comment.