From 9b8ddcbe4fe5ab387756a7460db96a073e736b00 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 14:46:28 +0200 Subject: [PATCH 1/5] Fix typo in ObjectType --- src/Type/ObjectType.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 322fe1540a..674c7660a9 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); @@ -1373,9 +1373,11 @@ public function changeSubtractedType(?Type $subtractedType): Type $classReflection = $this->getClassReflection(); $allowedSubTypesList = $classReflection !== null ? $classReflection->getAllowedSubTypes() : null; if ($allowedSubTypesList !== null) { + $preciseVerbosity = VerbosityLevel::precise(); + $allowedSubTypes = []; foreach ($allowedSubTypesList as $allowedSubType) { - $allowedSubTypes[$allowedSubType->describe(VerbosityLevel::precise())] = $allowedSubType; + $allowedSubTypes[$allowedSubType->describe($preciseVerbosity)] = $allowedSubType; } $originalAllowedSubTypes = $allowedSubTypes; @@ -1384,7 +1386,7 @@ public function changeSubtractedType(?Type $subtractedType): Type $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); $subtractedTypes = []; foreach ($subtractedTypesList as $type) { - $subtractedTypes[$type->describe(VerbosityLevel::precise())] = $type; + $subtractedTypes[$type->describe($preciseVerbosity)] = $type; } foreach ($subtractedTypes as $subType) { From d6f81655bac4a5c953f08317046961de48ca65e3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 15:00:28 +0200 Subject: [PATCH 2/5] Update ObjectType.php --- src/Type/ObjectType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 674c7660a9..e5a241760f 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1386,7 +1386,7 @@ public function changeSubtractedType(?Type $subtractedType): Type $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); $subtractedTypes = []; foreach ($subtractedTypesList as $type) { - $subtractedTypes[$type->describe($preciseVerbosity)] = $type; + $subtractedTypes[] = $type; } foreach ($subtractedTypes as $subType) { From 23e5e3f8ce942d41eea20ba0ed1a4251ac71b7d9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 15:07:28 +0200 Subject: [PATCH 3/5] simplify no longer necessary code --- src/Type/ObjectType.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index e5a241760f..a42bb846ac 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1384,12 +1384,7 @@ public function changeSubtractedType(?Type $subtractedType): Type $subtractedSubTypes = []; $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); - $subtractedTypes = []; - foreach ($subtractedTypesList as $type) { - $subtractedTypes[] = $type; - } - - foreach ($subtractedTypes as $subType) { + foreach ($subtractedTypesList as $subType) { foreach ($allowedSubTypes as $description => $allowedSubType) { if ($subType->equals($allowedSubType)) { $subtractedSubTypes[$description] = $subType; From 6aa620d9c5c72894657598c36b1b09d8c1f12b61 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 15:11:31 +0200 Subject: [PATCH 4/5] remove another unnecessary loop --- src/Type/ObjectType.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index a42bb846ac..47b27137f0 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1375,20 +1375,16 @@ public function changeSubtractedType(?Type $subtractedType): Type if ($allowedSubTypesList !== null) { $preciseVerbosity = VerbosityLevel::precise(); - $allowedSubTypes = []; - foreach ($allowedSubTypesList as $allowedSubType) { - $allowedSubTypes[$allowedSubType->describe($preciseVerbosity)] = $allowedSubType; - } - - $originalAllowedSubTypes = $allowedSubTypes; + $originalAllowedSubTypes = $allowedSubTypesList; $subtractedSubTypes = []; $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); foreach ($subtractedTypesList as $subType) { - foreach ($allowedSubTypes as $description => $allowedSubType) { + foreach ($allowedSubTypesList as $key => $allowedSubType) { if ($subType->equals($allowedSubType)) { + $description = $allowedSubType->describe($preciseVerbosity); $subtractedSubTypes[$description] = $subType; - unset($allowedSubTypes[$description]); + unset($allowedSubTypesList[$key]); continue 2; } } @@ -1396,8 +1392,8 @@ public function changeSubtractedType(?Type $subtractedType): Type return new self($this->className, $subtractedType); } - if (count($allowedSubTypes) === 1) { - return array_values($allowedSubTypes)[0]; + if (count($allowedSubTypesList) === 1) { + return array_values($allowedSubTypesList)[0]; } $subtractedSubTypes = array_values($subtractedSubTypes); From d6ebaadbda471472c9bcd6a7cfecfce2432d6e69 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 2 Jul 2024 15:14:47 +0200 Subject: [PATCH 5/5] improve variable names --- src/Type/ObjectType.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 47b27137f0..6a7b22e829 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1371,20 +1371,20 @@ public function changeSubtractedType(?Type $subtractedType): Type { if ($subtractedType !== null) { $classReflection = $this->getClassReflection(); - $allowedSubTypesList = $classReflection !== null ? $classReflection->getAllowedSubTypes() : null; - if ($allowedSubTypesList !== null) { + $allowedSubTypes = $classReflection !== null ? $classReflection->getAllowedSubTypes() : null; + if ($allowedSubTypes !== null) { $preciseVerbosity = VerbosityLevel::precise(); - $originalAllowedSubTypes = $allowedSubTypesList; + $originalAllowedSubTypes = $allowedSubTypes; $subtractedSubTypes = []; - $subtractedTypesList = TypeUtils::flattenTypes($subtractedType); - foreach ($subtractedTypesList as $subType) { - foreach ($allowedSubTypesList as $key => $allowedSubType) { + $subtractedTypes = TypeUtils::flattenTypes($subtractedType); + foreach ($subtractedTypes as $subType) { + foreach ($allowedSubTypes as $key => $allowedSubType) { if ($subType->equals($allowedSubType)) { $description = $allowedSubType->describe($preciseVerbosity); $subtractedSubTypes[$description] = $subType; - unset($allowedSubTypesList[$key]); + unset($allowedSubTypes[$key]); continue 2; } } @@ -1392,8 +1392,8 @@ public function changeSubtractedType(?Type $subtractedType): Type return new self($this->className, $subtractedType); } - if (count($allowedSubTypesList) === 1) { - return array_values($allowedSubTypesList)[0]; + if (count($allowedSubTypes) === 1) { + return array_values($allowedSubTypes)[0]; } $subtractedSubTypes = array_values($subtractedSubTypes);