diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 1ef20306ee..0abc8fd367 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1229,21 +1229,24 @@ public function getEnumCases(): array $className = $classReflection->getName(); - $cases = []; - foreach ($classReflection->getEnumCases() as $enumCase) { - $cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection); - } - if ($this->subtractedType !== null) { - $subtracedEnumCases = $this->subtractedType->getEnumCases(); - foreach ($cases as $i => $case) { - $caseName = $case->getEnumCaseName(); - foreach ($subtracedEnumCases as $subtracedCase) { - if ($caseName === $subtracedCase->getEnumCaseName()) { - unset($cases[$i]); - continue 2; - } + $subtracedEnumCaseNames = []; + + foreach ($this->subtractedType->getEnumCases() as $subtracedCase) { + $subtracedEnumCaseNames[$subtracedCase->getEnumCaseName()] = true; + } + + $cases = []; + foreach ($classReflection->getEnumCases() as $enumCase) { + if (array_key_exists($enumCase->getName(), $subtracedEnumCaseNames)) { + continue; } + $cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection); + } + } else { + $cases = []; + foreach ($classReflection->getEnumCases() as $enumCase) { + $cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection); } }