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 2 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
13 changes: 8 additions & 5 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
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
* }|null $columnDef
*
* @throws MappingException
Expand Down Expand Up @@ -2148,6 +2147,10 @@ public function setDiscriminatorColumn(DiscriminatorColumnMapping|array|null $co
throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']);
}

if (! isset($columnDef['options'])) {
$columnDef['options'] = [];
}
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved

$this->discriminatorColumn = DiscriminatorColumnMapping::fromMappingArray($columnDef);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Mapping/DiscriminatorColumnMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function __construct(
* type: string,
* fieldName: string,
* name: string,
* length?: int,
* columnDefinition?: string,
* enumType?: class-string<BackedEnum>,
* length?: int|null,
* columnDefinition?: string|null,
* enumType?: class-string<BackedEnum>|null,
* options?: array<string, mixed>,
VincentLanglet marked this conversation as resolved.
Show resolved Hide resolved
* } $mappingArray
*/
Expand Down
Loading