From b9d96266478461696d8db461a15601c7b4654d9a Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 6 Oct 2023 22:17:51 +0200 Subject: [PATCH] Fix possible internal error when analysing code with enums on PHP 7.x --- src/Reflection/ClassReflection.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Reflection/ClassReflection.php b/src/Reflection/ClassReflection.php index 2a7c5a3afe..2d768f7678 100644 --- a/src/Reflection/ClassReflection.php +++ b/src/Reflection/ClassReflection.php @@ -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 @@ -651,10 +654,6 @@ public function hasEnumCase(string $name): bool return false; } - if (!$this->reflection instanceof ReflectionEnum) { - return false; - } - return $this->reflection->hasCase($name); } @@ -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(); }