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

Drop selectable extension for collection interface #33

Closed
wants to merge 1 commit into from

Conversation

alcaeus
Copy link

@alcaeus alcaeus commented Jul 27, 2018

Suggesting this for 0.11 since it might be considered a BC break. From the README:

Adds missing matching method on Doctrine\Common\Collections\Collection

The collection interface does not support the matching method, so the part of the extension that pretends matching exists, is downright dangeous IMO. Instead, intersection types should be used instead of the Collection interface, e.g. @var Collection&Selectable.

@ondrejmirtes
Copy link
Member

Hi,
I understand this from the typesystem point of view, but let's be pragmatic here: all the collections in real-world use implement this Selectable interface, see:

That's why I implemented this extension, the error message is annoying because it's too pedantic for practical use.

@alcaeus
Copy link
Author

alcaeus commented Jul 30, 2018

That's why I implemented this extension, the error message is annoying because it's too pedantic for practical use.

That's a very disappointing reason: I've got a project using both ORM and MongoDB ODM and can't use this library because of the extension: the PersistentCollection implemented in ODM does not implement the Selectable interface, thus hiding errors that can very well appear when people don't pay attention.

I hope you reconsider your opinion - "the error message is annoying" should not be a reason to throw proper typing out the window. Just because most people do it wrong (and maybe the interfaces have been designed wrong years ago) doesn't mean we should have such code by default.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 30, 2018 via email

@alcaeus
Copy link
Author

alcaeus commented Jul 30, 2018

Just because it wouldn’t report a specific error doesn’t mean it’s unusable.

Yes, it does: instead of finding errors, which PHPStan is great at, this extension hides errors for the sake of convenience instead of promoting proper typing of those interfaces. That's enough reason for me not to use the extension.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 30, 2018 via email

@alcaeus
Copy link
Author

alcaeus commented Jul 30, 2018

it promotes calling “matching” on the Collection interface

If you could please point out where we do that, I’ll see to it that it’s updated accordingly. As long as the collection interface doesn’t contain a “matching” method we shouldn’t advocate using it without proper type hints and type checking. At the same time, this shouldn’t be default behavior in a static analyzer.

@ondrejmirtes
Copy link
Member

The matching() method is presented as part of the Collection interface here: https://www.doctrine-project.org/projects/doctrine-collections/en/latest/index.html#matching

IMHO Selectable and Collection interfaces should just be merged, that would be the easiest path going forward.

@stof
Copy link
Contributor

stof commented Jul 30, 2018

@ondrejmirtes but that cannot be done without a major version of doctrine/collections as that's a BC break.

@ondrejmirtes
Copy link
Member

Solved in an easier way: ce2837a

@alcaeus alcaeus deleted the drop-selectable-extensions branch November 1, 2018 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants