Skip to content

Commit

Permalink
remove another unnecessary loop
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jul 2, 2024
1 parent 23e5e3f commit 6aa620d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1375,29 +1375,25 @@ 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;
}
}

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);
Expand Down

0 comments on commit 6aa620d

Please sign in to comment.