From 9b104b443432e2ff716d894d6d11071af74b9583 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Nov 2024 21:25:58 +0100 Subject: [PATCH 1/2] Lazier return in `UnionType->isSuperTypeOfWithReason()` --- src/Type/UnionType.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 6f4cbf462b..f5b927b9f6 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -245,7 +245,16 @@ public function isSuperTypeOfWithReason(Type $otherType): IsSuperTypeOfResult return $otherType->isSubTypeOfWithReason($this); } - $result = IsSuperTypeOfResult::createNo()->or(...array_map(static fn (Type $innerType) => $innerType->isSuperTypeOfWithReason($otherType), $this->types)); + $results = []; + foreach ($this->types as $innerType) { + $result = $innerType->isSuperTypeOfWithReason($otherType); + if ($result->yes()) { + return $result; + } + $results[] = $result; + } + + $result = IsSuperTypeOfResult::createNo()->or(...$results); if ($result->yes()) { return $result; } From 6b13264ce2a9a352171f7de11bad90566debd3bb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Nov 2024 22:26:09 +0100 Subject: [PATCH 2/2] simplify --- src/Type/UnionType.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index f5b927b9f6..14eb812267 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -253,11 +253,7 @@ public function isSuperTypeOfWithReason(Type $otherType): IsSuperTypeOfResult } $results[] = $result; } - $result = IsSuperTypeOfResult::createNo()->or(...$results); - if ($result->yes()) { - return $result; - } if ($otherType instanceof TemplateUnionType) { return $result->or($otherType->isSubTypeOfWithReason($this));