-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make paginator covariant #10002
Make paginator covariant #10002
Conversation
No suggestion yet, but can you add a piece of code under |
I added as much tests as possible ^^ |
} | ||
|
||
/** | ||
* @psalm-return Paginator<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't be possible if Paginator wasn't covariant.
*/ | ||
function test(PaginatorFactory $catPaginatorFactory): ?Animal | ||
{ | ||
return getFirstAnimal($catPaginatorFactory->createPaginator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing a Paginator to getFirstAnimal wouldn't be possible if Paginator wasn't covariant
Please squash your commits, and retarget to 2.14.x: this is an improvement and there is a small BC-break. |
actually, |
Done |
* 2.14.x: Bump Ubuntu version and shared workflows (doctrine#10020) Make paginator covariant (doctrine#10002) Fail gracefully if EM could not be constructed in tests (doctrine#10008)
hey @VincentLanglet sorry for coming back after this MR is merged a long time ago 😬 we want to update to the recent 2.14.1 version. our problem is that we are using Just to be sure: the migration path would simply be exchanging this with thanks in advance ✌️ |
Sure. |
see https://phpstan.org/blog/whats-up-with-template-covariant
see https://psalm.dev/docs/annotating_code/templated_annotations/
A method which accepts
Paginator<Animal>
should be able to acceptPaginator<Cat>
.I received the error
It's because the template of ArrayIterator is not covariant.
But the template for Traversable is covariant.
It makes sens to use Traversable instead of ArrayIterator as return type because
ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Countable
the issue is the ArrayAccess.
If you preferred I can use somethink like
Any suggestion @greg0ire ?