Skip to content

Commit

Permalink
Fix possible internal error when analysing code with enums on PHP 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 6, 2023
1 parent d6a576a commit b9d9626
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,12 @@ public function isTrait(): bool
return $this->reflection->isTrait();
}

/**
* @phpstan-assert-if-true ReflectionEnum $this->reflection
*/
public function isEnum(): bool
{
return $this->reflection->isEnum();
return $this->reflection->isEnum() && $this->reflection instanceof ReflectionEnum;
}

public function isReadOnly(): bool
Expand Down Expand Up @@ -651,10 +654,6 @@ public function hasEnumCase(string $name): bool
return false;
}

if (!$this->reflection instanceof ReflectionEnum) {
return false;
}

return $this->reflection->hasCase($name);
}

Expand All @@ -663,7 +662,7 @@ public function hasEnumCase(string $name): bool
*/
public function getEnumCases(): array
{
if (!$this->reflection instanceof ReflectionEnum) {
if (!$this->isEnum()) {
throw new ShouldNotHappenException();
}

Expand Down

0 comments on commit b9d9626

Please sign in to comment.