From a5bf9bb96a0b2edbefd8355a61fb799fae03cec8 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 22 Feb 2024 09:12:39 +0100 Subject: [PATCH] Be less restrictive in DiscriminatorColumnMapping phpdoc (#11226) * Be less restrictive in params * Allow null options * Simplify expression * Fix ci * Add support for null --- src/Mapping/ClassMetadata.php | 19 +++++++------------ src/Mapping/DiscriminatorColumnMapping.php | 10 +++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index 0d9889b6e77..3f5b1c77732 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -2108,13 +2108,12 @@ public function addEntityListener(string $eventName, string $class, string $meth * @param DiscriminatorColumnMapping|mixed[]|null $columnDef * @psalm-param DiscriminatorColumnMapping|array{ * name: string|null, - * fieldName?: string, - * type?: string, - * length?: int, + * fieldName?: string|null, + * type?: string|null, + * length?: int|null, * columnDefinition?: string|null, * enumType?: class-string|null, - * options?:array|null + * options?: array|null * }|null $columnDef * * @throws MappingException @@ -2136,13 +2135,9 @@ public function setDiscriminatorColumn(DiscriminatorColumnMapping|array|null $co throw MappingException::duplicateColumnName($this->name, $columnDef['name']); } - if (! isset($columnDef['fieldName'])) { - $columnDef['fieldName'] = $columnDef['name']; - } - - if (! isset($columnDef['type'])) { - $columnDef['type'] = 'string'; - } + $columnDef['fieldName'] ??= $columnDef['name']; + $columnDef['type'] ??= 'string'; + $columnDef['options'] ??= []; if (in_array($columnDef['type'], ['boolean', 'array', 'object', 'datetime', 'time', 'date'], true)) { throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']); diff --git a/src/Mapping/DiscriminatorColumnMapping.php b/src/Mapping/DiscriminatorColumnMapping.php index cc23fdfdb3b..4ccb71c4b36 100644 --- a/src/Mapping/DiscriminatorColumnMapping.php +++ b/src/Mapping/DiscriminatorColumnMapping.php @@ -39,10 +39,10 @@ public function __construct( * type: string, * fieldName: string, * name: string, - * length?: int, - * columnDefinition?: string, - * enumType?: class-string, - * options?: array, + * length?: int|null, + * columnDefinition?: string|null, + * enumType?: class-string|null, + * options?: array|null, * } $mappingArray */ public static function fromMappingArray(array $mappingArray): self @@ -58,7 +58,7 @@ public static function fromMappingArray(array $mappingArray): self } if (property_exists($mapping, $key)) { - $mapping->$key = $value; + $mapping->$key = $value ?? $mapping->$key; } else { throw new Exception('Unknown property ' . $key . ' on class ' . static::class); }