Skip to content

Commit

Permalink
Optimization?
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 3, 2022
1 parent 2c9273e commit 91c7507
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public static function containsNull(Type $type): bool
public static function union(Type ...$types): Type
{
$typesCount = count($types);
if ($typesCount === 0) {
return new NeverType();
}

$benevolentTypes = [];
$benevolentUnionObject = null;
Expand Down Expand Up @@ -126,6 +129,10 @@ public static function union(Type ...$types): Type
$typesCount += count($typesInner) - 1;
}

if ($typesCount === 1) {
return $types[0];
}

$arrayTypes = [];
$arrayAccessoryTypes = [];
$scalarTypes = [];
Expand Down

0 comments on commit 91c7507

Please sign in to comment.