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 8b1af0f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,15 @@ 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));
if ($result->yes()) {
return $result;
$results = [];
foreach ($this->types as $innerType) {
$result = $innerType->isSuperTypeOf($otherType);
if ($result->yes()) {
return $result;
}
$results[] = $result;
}
$result = IsSuperTypeOfResult::createNo()->or(...$results);

if ($otherType instanceof TemplateUnionType) {
return $result->or($otherType->isSubTypeOf($this));
Expand Down

0 comments on commit 8b1af0f

Please sign in to comment.