Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Dec 21, 2022
1 parent 095fe1d commit cc710e8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Type/TypeCombinator.php
Expand Up @@ -278,18 +278,22 @@ public static function union(Type ...$types): Type
[$a, $b] = $compareResult;
if ($a !== null) {
$innerTypes[$key] = $a;
$types[$i] = new UnionType($innerTypes, true);
$types[$i] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
array_splice($types, $j--, 1);
$typesCount--;
continue 2;
}
if ($b !== null) {
$types[$j] = $b;
unset($innerTypes[$key]);
$types[$i] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
continue 2;
}
}
if (count($innerTypes) === 0) {
array_splice($types, $i--, 1);
$typesCount--;
continue 2;
}
$types[$i] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
continue;
}

Expand All @@ -303,18 +307,22 @@ public static function union(Type ...$types): Type
[$a, $b] = $compareResult;
if ($a !== null) {
$innerTypes[$key] = $a;
$types[$j] = new UnionType($innerTypes, true);
$types[$j] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
array_splice($types, $i--, 1);
$typesCount--;
continue 3;
}
if ($b !== null) {
$types[$i] = $b;
unset($innerTypes[$key]);
$types[$j] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
continue 2;
}
}
if (count($innerTypes) === 0) {
array_splice($types, $j--, 1);
$typesCount--;
continue 1;
}
$types[$j] = count($innerTypes) === 1 ? reset($innerTypes) : new UnionType(array_values($innerTypes), true);
continue;
}

Expand Down

0 comments on commit cc710e8

Please sign in to comment.