Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be less restrictive in DiscriminatorColumnMapping phpdoc #11226

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an isset check

if (! isset($columnDef['fieldName'])) {
                $columnDef['fieldName'] = $columnDef['name'];
            }

so null is handled

* type?: string|null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an isset check

if (! isset($columnDef['type'])) {
                $columnDef['type'] = 'string';
            }

so null is handled.

* length?: int|null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiscriminatorColumnMapping use

public int|null $length = null;

so a null length seems valid.

* 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
Loading