Skip to content

Commit 91c7507

Browse files
committed
Optimization?
1 parent 2c9273e commit 91c7507

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Type/TypeCombinator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public static function containsNull(Type $type): bool
9595
public static function union(Type ...$types): Type
9696
{
9797
$typesCount = count($types);
98+
if ($typesCount === 0) {
99+
return new NeverType();
100+
}
98101

99102
$benevolentTypes = [];
100103
$benevolentUnionObject = null;
@@ -126,6 +129,10 @@ public static function union(Type ...$types): Type
126129
$typesCount += count($typesInner) - 1;
127130
}
128131

132+
if ($typesCount === 1) {
133+
return $types[0];
134+
}
135+
129136
$arrayTypes = [];
130137
$arrayAccessoryTypes = [];
131138
$scalarTypes = [];

0 commit comments

Comments
 (0)