Skip to content

Commit

Permalink
Narrow ReflectionEnum::getBackingType after ReflectionEnum::isBacked
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMe committed Nov 20, 2023
1 parent 49f1667 commit 2e86a2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stubs/ReflectionEnum.stub
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class ReflectionEnum extends ReflectionClass
*/
public function getCase(string $name): ReflectionEnumUnitCase {}

/**
* @phpstan-assert-if-true !null $this->getBackingType()
*/
public function isBacked(): bool {}
}
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/data/enum-reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ReflectionEnum;
use ReflectionEnumBackedCase;
use ReflectionEnumUnitCase;
use ReflectionType;
use function PHPStan\Testing\assertType;

enum Foo: int
Expand Down Expand Up @@ -41,3 +42,9 @@ public function doFoo(): void
}

}

$r = new ReflectionEnum(Foo::class);
assertType(ReflectionType::class . '|null', $r->getBackingType());
if ($r->isBacked()) {
assertType(ReflectionType::class, $r->getBackingType());
}

0 comments on commit 2e86a2d

Please sign in to comment.