Skip to content

Commit 9bebc23

Browse files
committed
Early return in UnionType->isSuperTypeOf()
1 parent 14d2bed commit 9bebc23

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Type/UnionType.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,16 @@ public function isSuperTypeOf(Type $otherType): IsSuperTypeOfResult
244244
return $otherType->isSubTypeOf($this);
245245
}
246246

247-
$result = IsSuperTypeOfResult::createNo()->or(...array_map(static fn (Type $innerType) => $innerType->isSuperTypeOf($otherType), $this->types));
247+
$results = [];
248+
foreach ($this->types as $innerType) {
249+
$result = $innerType->isSuperTypeOf($otherType);
250+
if ($result->yes()) {
251+
return $result;
252+
}
253+
$results[] = $result;
254+
}
255+
256+
$result = IsSuperTypeOfResult::createNo()->or(...$results);
248257
if ($result->yes()) {
249258
return $result;
250259
}

0 commit comments

Comments
 (0)