Skip to content

Commit

Permalink
Early return in UnionType->isSuperTypeOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Nov 30, 2024
1 parent 14d2bed commit 9bebc23
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,16 @@ public function isSuperTypeOf(Type $otherType): IsSuperTypeOfResult
return $otherType->isSubTypeOf($this);
}

$result = IsSuperTypeOfResult::createNo()->or(...array_map(static fn (Type $innerType) => $innerType->isSuperTypeOf($otherType), $this->types));
$results = [];
foreach ($this->types as $innerType) {
$result = $innerType->isSuperTypeOf($otherType);
if ($result->yes()) {
return $result;
}
$results[] = $result;
}

$result = IsSuperTypeOfResult::createNo()->or(...$results);
if ($result->yes()) {
return $result;
}
Expand Down

0 comments on commit 9bebc23

Please sign in to comment.