Skip to content

Commit f4c820f

Browse files
committed
fix union type
1 parent 9e426f7 commit f4c820f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/UnionParameter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ public function __construct(
3939
private ParametersInterface $parameters,
4040
private string $description = '',
4141
) {
42-
$this->type = $this->type();
4342
if ($parameters->count() < 2) {
4443
throw new LogicException(
4544
(string) message(
4645
'Must pass at least two parameters for union'
4746
)
4847
);
4948
}
50-
49+
$types = array_map(
50+
fn (ParameterInterface $parameter): string => $parameter->type()->typeHinting(),
51+
iterator_to_array($this->parameters)
52+
);
53+
$this->type = new Type(TypeInterface::UNION, ...$types);
5154
$this->parameters = $parameters;
5255
}
5356

tests/UnionParameterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testConstruct(): void
4545
bar: int()
4646
);
4747
$parameter = new UnionParameter($parameters);
48+
$this->assertSame('string|int', $parameter->type()->typeHinting());
4849
$this->assertSame(
4950
TypeInterface::UNION,
5051
$parameter->type()->primitive()

0 commit comments

Comments
 (0)