Skip to content

Commit a5bf9bb

Browse files
Be less restrictive in DiscriminatorColumnMapping phpdoc (#11226)
* Be less restrictive in params * Allow null options * Simplify expression * Fix ci * Add support for null
1 parent bc5efd4 commit a5bf9bb

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/Mapping/ClassMetadata.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -2108,13 +2108,12 @@ public function addEntityListener(string $eventName, string $class, string $meth
21082108
* @param DiscriminatorColumnMapping|mixed[]|null $columnDef
21092109
* @psalm-param DiscriminatorColumnMapping|array{
21102110
* name: string|null,
2111-
* fieldName?: string,
2112-
* type?: string,
2113-
* length?: int,
2111+
* fieldName?: string|null,
2112+
* type?: string|null,
2113+
* length?: int|null,
21142114
* columnDefinition?: string|null,
21152115
* enumType?: class-string<BackedEnum>|null,
2116-
* options?:array<string,
2117-
* mixed>|null
2116+
* options?: array<string, mixed>|null
21182117
* }|null $columnDef
21192118
*
21202119
* @throws MappingException
@@ -2136,13 +2135,9 @@ public function setDiscriminatorColumn(DiscriminatorColumnMapping|array|null $co
21362135
throw MappingException::duplicateColumnName($this->name, $columnDef['name']);
21372136
}
21382137

2139-
if (! isset($columnDef['fieldName'])) {
2140-
$columnDef['fieldName'] = $columnDef['name'];
2141-
}
2142-
2143-
if (! isset($columnDef['type'])) {
2144-
$columnDef['type'] = 'string';
2145-
}
2138+
$columnDef['fieldName'] ??= $columnDef['name'];
2139+
$columnDef['type'] ??= 'string';
2140+
$columnDef['options'] ??= [];
21462141

21472142
if (in_array($columnDef['type'], ['boolean', 'array', 'object', 'datetime', 'time', 'date'], true)) {
21482143
throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']);

src/Mapping/DiscriminatorColumnMapping.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function __construct(
3939
* type: string,
4040
* fieldName: string,
4141
* name: string,
42-
* length?: int,
43-
* columnDefinition?: string,
44-
* enumType?: class-string<BackedEnum>,
45-
* options?: array<string, mixed>,
42+
* length?: int|null,
43+
* columnDefinition?: string|null,
44+
* enumType?: class-string<BackedEnum>|null,
45+
* options?: array<string, mixed>|null,
4646
* } $mappingArray
4747
*/
4848
public static function fromMappingArray(array $mappingArray): self
@@ -58,7 +58,7 @@ public static function fromMappingArray(array $mappingArray): self
5858
}
5959

6060
if (property_exists($mapping, $key)) {
61-
$mapping->$key = $value;
61+
$mapping->$key = $value ?? $mapping->$key;
6262
} else {
6363
throw new Exception('Unknown property ' . $key . ' on class ' . static::class);
6464
}

0 commit comments

Comments
 (0)