Skip to content

Commit

Permalink
Fix reporting missing iterable value type in intersection types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 9, 2021
1 parent e9968bd commit 153179e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Rules/MissingTypehintCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -94,7 +95,7 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array
}
$iterablesWithMissingValueTypehint[] = $type;
}
if ($this->deepInspectTypes) {
if ($this->deepInspectTypes && !$type instanceof IntersectionType) {
return $traverse($type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MissingMethodReturnTypehintRuleTest extends \PHPStan\Testing\RuleTestCase
protected function getRule(): \PHPStan\Rules\Rule
{
$broker = $this->createReflectionProvider();
return new MissingMethodReturnTypehintRule(new MissingTypehintCheck($broker, true, true, true));
return new MissingMethodReturnTypehintRule(new MissingTypehintCheck($broker, true, true, true, [], true));
}

public function testRule(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,14 @@ public function doFoo(): callable
}

}

class IterableIntersection
{

/** @return FooInterface[]|\Traversable */
public function doFoo(): \Traversable
{

}

}

0 comments on commit 153179e

Please sign in to comment.