From 702b4223b9b10e2dd611c82179171e55dea7cc8f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Nov 2024 21:22:26 +0100 Subject: [PATCH] Early return in `UnionType->isSuperTypeOf()` --- src/Type/UnionType.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 5d7627b30..c69888cf3 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -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));