Skip to content

Commit adb23fb

Browse files
committed
Fix double rendering of union types
1 parent 8e110fd commit adb23fb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ValueObject/Type.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ public function getTypeHint(bool $renderUnion = false): ?string
177177
if ($renderUnion) {
178178
$typeHint = [];
179179
foreach ($this->getUnionTypes() as $unionType) {
180-
$typeHint[] = $unionType->getTypeHint();
180+
$unionTypeHint = $unionType->getTypeHint();
181+
if (!in_array($unionTypeHint, $typeHint)) {
182+
$typeHint[] = $unionTypeHint;
183+
}
181184
}
182185
if ($this->isNullable() && !in_array('mixed', $typeHint)) {
183186
array_unshift($typeHint, 'null');

tests/ValueObject/TypeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,12 @@ public function testEnumStringValueNullableAndClass(): void
353353
$this->assertNull($type->getTypeHint());
354354
$this->assertNull($type->getTypeHint(true));
355355
}
356+
357+
public function testDontDoubleRenderUnionTypes(): void
358+
{
359+
$type = Type::fromString('array<int>');
360+
$type->addUnion('array<string>');
361+
362+
$this->assertSame('array', $type->getTypeHint(true));
363+
}
356364
}

0 commit comments

Comments
 (0)