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

Fix discriminatorColumn phpdoc #9168

Merged
merged 3 commits into from
Nov 11, 2021
Merged

Fix discriminatorColumn phpdoc #9168

merged 3 commits into from
Nov 11, 2021

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Nov 1, 2021

Hi @greg0ire, since the property is not initialized, the phpdoc should allow null.
This avoid a phpstan error if we're doing an isset check on the property.

The other solution is to initialize the value to [] but tests are failing

@VincentLanglet VincentLanglet changed the title Fix discriminatorColumn phpdoc Use discriminatorColumn default value to respect the phpdoc Nov 1, 2021
@VincentLanglet VincentLanglet changed the title Use discriminatorColumn default value to respect the phpdoc Fix discriminatorColumn phpdoc Nov 1, 2021
@VincentLanglet
Copy link
Contributor Author

Psalm is failing because null check are not done in the ORM code.
Is the value always set ?

@greg0ire
Copy link
Member

greg0ire commented Nov 3, 2021

Hi Vincent!

Is the value always set ?

Maybe not always, but as soon as there is inheritance, it probably is:

if (isset($classAttributes[Mapping\DiscriminatorColumn::class])) {
$discrColumnAttribute = $classAttributes[Mapping\DiscriminatorColumn::class];
$metadata->setDiscriminatorColumn(
[
'name' => $discrColumnAttribute->name,
'type' => $discrColumnAttribute->type ?: 'string',
'length' => $discrColumnAttribute->length ?: 255,
'columnDefinition' => $discrColumnAttribute->columnDefinition,
]
);
} else {
$metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]);
}

@VincentLanglet
Copy link
Contributor Author

I added some assert checks to fix the psalm build.
The others failing tests are not related, since it's already failing on the 2.10.x branch.

@greg0ire
Copy link
Member

greg0ire commented Nov 8, 2021

Looks like the failure is due to doctrine/dbal@317c05620 . We are asserting against the generated SQL 😬

@greg0ire
Copy link
Member

greg0ire commented Nov 8, 2021

Blocked by #9181

@greg0ire greg0ire closed this Nov 11, 2021
@greg0ire greg0ire reopened this Nov 11, 2021
@VincentLanglet
Copy link
Contributor Author

Thanks, tests are fine now @greg0ire if you find some time to review :)

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

All these assert calls look a bit clumsy, repetitive, and are a code smell…
How about introducing a final public function discriminatorColumn() in ClassMetadataInfo that performs the assertion, or better, throws a LogicException saying that this class probably does not have inheritance mapping?

@derrabus derrabus merged commit 9a74ae6 into doctrine:2.10.x Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants