Skip to content

Commit

Permalink
Be less restrictive in DiscriminatorColumnMapping phpdoc (#11226)
Browse files Browse the repository at this point in the history
* Be less restrictive in params

* Allow null options

* Simplify expression

* Fix ci

* Add support for null
  • Loading branch information
VincentLanglet committed Feb 22, 2024
1 parent bc5efd4 commit a5bf9bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
19 changes: 7 additions & 12 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<BackedEnum>|null,
* options?:array<string,
* mixed>|null
* options?: array<string, mixed>|null
* }|null $columnDef
*
* @throws MappingException
Expand All @@ -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']);
Expand Down
10 changes: 5 additions & 5 deletions src/Mapping/DiscriminatorColumnMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function __construct(
* type: string,
* fieldName: string,
* name: string,
* length?: int,
* columnDefinition?: string,
* enumType?: class-string<BackedEnum>,
* options?: array<string, mixed>,
* length?: int|null,
* columnDefinition?: string|null,
* enumType?: class-string<BackedEnum>|null,
* options?: array<string, mixed>|null,
* } $mappingArray
*/
public static function fromMappingArray(array $mappingArray): self
Expand All @@ -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);
}
Expand Down

0 comments on commit a5bf9bb

Please sign in to comment.