From f546c37a4da85a7ffb4c0718a01479c690776322 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 17:18:53 +0200 Subject: [PATCH] Fix typo in ObjectType --- src/Type/ObjectType.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 322fe1540a..6a7b22e829 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1230,15 +1230,15 @@ public function getEnumCases(): array $className = $classReflection->getName(); if ($this->subtractedType !== null) { - $subtracedEnumCaseNames = []; + $subtractedEnumCaseNames = []; foreach ($this->subtractedType->getEnumCases() as $subtractedCase) { - $subtracedEnumCaseNames[$subtractedCase->getEnumCaseName()] = true; + $subtractedEnumCaseNames[$subtractedCase->getEnumCaseName()] = true; } $cases = []; foreach ($classReflection->getEnumCases() as $enumCase) { - if (array_key_exists($enumCase->getName(), $subtracedEnumCaseNames)) { + if (array_key_exists($enumCase->getName(), $subtractedEnumCaseNames)) { continue; } $cases[] = new EnumCaseObjectType($className, $enumCase->getName(), $classReflection); @@ -1371,27 +1371,20 @@ public function changeSubtractedType(?Type $subtractedType): Type { if ($subtractedType !== null) { $classReflection = $this->getClassReflection(); - $allowedSubTypesList = $classReflection !== null ? $classReflection->getAllowedSubTypes() : null; - if ($allowedSubTypesList !== null) { - $allowedSubTypes = []; - foreach ($allowedSubTypesList as $allowedSubType) { - $allowedSubTypes[$allowedSubType->describe(VerbosityLevel::precise())] = $allowedSubType; - } + $allowedSubTypes = $classReflection !== null ? $classReflection->getAllowedSubTypes() : null; + if ($allowedSubTypes !== null) { + $preciseVerbosity = VerbosityLevel::precise(); $originalAllowedSubTypes = $allowedSubTypes; $subtractedSubTypes = []; - $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); - $subtractedTypes = []; - foreach ($subtractedTypesList as $type) { - $subtractedTypes[$type->describe(VerbosityLevel::precise())] = $type; - } - + $subtractedTypes = TypeUtils::flattenTypes($subtractedType); foreach ($subtractedTypes as $subType) { - foreach ($allowedSubTypes as $description => $allowedSubType) { + foreach ($allowedSubTypes as $key => $allowedSubType) { if ($subType->equals($allowedSubType)) { + $description = $allowedSubType->describe($preciseVerbosity); $subtractedSubTypes[$description] = $subType; - unset($allowedSubTypes[$description]); + unset($allowedSubTypes[$key]); continue 2; } }