Skip to content

Commit 362503d

Browse files
authored
Merge pull request #1563 from scyzoryck/fix-issue-1562
fix(unions): Filter out null type
2 parents 43404be + 1946af2 commit 362503d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Metadata/Driver/TypedPropertiesDriver.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
113113
} elseif ($this->shouldTypeHintUnion($reflectionType)) {
114114
$propertyMetadata->setType([
115115
'name' => 'union',
116-
'params' => [$this->reorderTypes(array_map(fn (string $type) => $this->typeParser->parse($type), $reflectionType->getTypes()))],
116+
'params' => [
117+
$this->reorderTypes(
118+
array_map(
119+
fn (string $type) => $this->typeParser->parse($type),
120+
array_filter($reflectionType->getTypes(), [$this, 'shouldTypeHint']),
121+
),
122+
),
123+
],
117124
]);
118125
}
119126
} catch (ReflectionException $e) {

tests/Fixtures/TypedProperties/UnionTypedProperties.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class UnionTypedProperties
88
{
99
private int|bool|float|string $data;
1010

11+
private int|bool|float|string|null $nullableData;
12+
1113
public function __construct($data)
1214
{
1315
$this->data = $data;

0 commit comments

Comments
 (0)