Skip to content

Commit

Permalink
Merge pull request #1563 from scyzoryck/fix-issue-1562
Browse files Browse the repository at this point in the history
fix(unions): Filter out null type
  • Loading branch information
scyzoryck authored Oct 31, 2024
2 parents 43404be + 1946af2 commit 362503d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Metadata/Driver/TypedPropertiesDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
} elseif ($this->shouldTypeHintUnion($reflectionType)) {
$propertyMetadata->setType([
'name' => 'union',
'params' => [$this->reorderTypes(array_map(fn (string $type) => $this->typeParser->parse($type), $reflectionType->getTypes()))],
'params' => [
$this->reorderTypes(
array_map(
fn (string $type) => $this->typeParser->parse($type),
array_filter($reflectionType->getTypes(), [$this, 'shouldTypeHint']),
),
),
],
]);
}
} catch (ReflectionException $e) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/TypedProperties/UnionTypedProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class UnionTypedProperties
{
private int|bool|float|string $data;

private int|bool|float|string|null $nullableData;

public function __construct($data)
{
$this->data = $data;
Expand Down

0 comments on commit 362503d

Please sign in to comment.