Skip to content

Commit b9d9626

Browse files
committed
Fix possible internal error when analysing code with enums on PHP 7.x
1 parent d6a576a commit b9d9626

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: src/Reflection/ClassReflection.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,12 @@ public function isTrait(): bool
608608
return $this->reflection->isTrait();
609609
}
610610

611+
/**
612+
* @phpstan-assert-if-true ReflectionEnum $this->reflection
613+
*/
611614
public function isEnum(): bool
612615
{
613-
return $this->reflection->isEnum();
616+
return $this->reflection->isEnum() && $this->reflection instanceof ReflectionEnum;
614617
}
615618

616619
public function isReadOnly(): bool
@@ -651,10 +654,6 @@ public function hasEnumCase(string $name): bool
651654
return false;
652655
}
653656

654-
if (!$this->reflection instanceof ReflectionEnum) {
655-
return false;
656-
}
657-
658657
return $this->reflection->hasCase($name);
659658
}
660659

@@ -663,7 +662,7 @@ public function hasEnumCase(string $name): bool
663662
*/
664663
public function getEnumCases(): array
665664
{
666-
if (!$this->reflection instanceof ReflectionEnum) {
665+
if (!$this->isEnum()) {
667666
throw new ShouldNotHappenException();
668667
}
669668

0 commit comments

Comments
 (0)