Skip to content

Commit 70b2e0d

Browse files
committed
Prevent unnecessary work in IntersectionType
1 parent 2681e50 commit 70b2e0d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Type/IntersectionType.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,16 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
266266
return $otherType->isSuperTypeOf($this);
267267
}
268268

269-
$result = IsSuperTypeOfResult::maxMin(...array_map(static fn (Type $innerType) => $otherType->isSuperTypeOf($innerType), $this->types));
269+
$results = [];
270+
foreach ($this->types as $innerType) {
271+
$isSuperTypeOf = $otherType->isSuperTypeOf($innerType);
272+
if ($isSuperTypeOf->yes()) {
273+
return IsSuperTypeOfResult::createYes();
274+
}
275+
$results[] = $isSuperTypeOf;
276+
}
277+
$result = IsSuperTypeOfResult::maxMin(...$results);
278+
270279
if (
271280
!$result->no()
272281
&& $this->isOversizedArray()->yes()
@@ -280,7 +289,16 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
280289

281290
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
282291
{
283-
$result = AcceptsResult::maxMin(...array_map(static fn (Type $innerType) => $acceptingType->accepts($innerType, $strictTypes), $this->types));
292+
$results = [];
293+
foreach ($this->types as $innerType) {
294+
$isAcceptedBy = $acceptingType->isAcceptedBy($innerType, $strictTypes);
295+
296+
if ($isAcceptedBy->yes()) {
297+
return AcceptsResult::createYes();
298+
}
299+
}
300+
$result = AcceptsResult::maxMin(...$results);
301+
284302
if ($this->isOversizedArray()->yes()) {
285303
if (!$result->no()) {
286304
return AcceptsResult::createYes();

0 commit comments

Comments
 (0)