Skip to content

Commit

Permalink
Fix TemplateTypeMap::isEmpty()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 16, 2021
1 parent cee6f68 commit f7250db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Type/Generic/TemplateTypeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public static function createEmpty(): self

public function isEmpty(): bool
{
return count($this->types) === 0;
return $this->count() === 0;
}

public function count(): int
{
return count($this->types);
return count($this->types + $this->lowerBoundTypes);
}

/** @return array<string,\PHPStan\Type\Type> */
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Type/Generic/TemplateTypeMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function dataUnionWithLowerBoundTypes(): iterable
'T' => new ObjectType(\Exception::class),
]))->convertToLowerBoundTypes();

yield [
$map,
\Exception::class,
];

yield [
$map->union(new TemplateTypeMap([
'T' => new ObjectType(\InvalidArgumentException::class),
Expand Down Expand Up @@ -51,6 +56,7 @@ public function dataUnionWithLowerBoundTypes(): iterable
/** @dataProvider dataUnionWithLowerBoundTypes */
public function testUnionWithLowerBoundTypes(TemplateTypeMap $map, string $expectedTDescription): void
{
$this->assertFalse($map->isEmpty());
$t = $map->getType('T');
$this->assertNotNull($t);
$this->assertSame($expectedTDescription, $t->describe(VerbosityLevel::precise()));
Expand Down

0 comments on commit f7250db

Please sign in to comment.