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

Introduce convenience methods to narrow types #10701

Merged
merged 1 commit into from
May 15, 2023

Conversation

greg0ire
Copy link
Member

These methods assert the type of the mapping provided by the collection according to the name of the class they are in: the one to many persister only ever deals with one to many associations, and the many to many persister only ever deals with many to many associations.

These methods assert the type of the mapping provided by the collection
according to the name of the class they are in: the one to many
persister only ever deals with one to many associations, and the many to
many persister only ever deals with many to many associations.
{
$mapping = $collection->getMapping();

assert($mapping instanceof ManyToManyAssociationMapping);
Copy link
Member

Choose a reason for hiding this comment

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

Is this assert even needed here when the type hint only allows AssociationMapping instances that implement ManyToManyAssociationMapping?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, otherwise SA will complain that nothing proves we return that type although we claim we do.

@greg0ire greg0ire added this to the 3.0.0 milestone May 15, 2023
@greg0ire greg0ire merged commit a55c72b into doctrine:3.0.x May 15, 2023
@greg0ire greg0ire deleted the convenience branch May 15, 2023 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants