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

Extending Doctrine ArrayCollection #271

Open
bramcordie opened this issue Apr 9, 2021 · 0 comments
Open

Extending Doctrine ArrayCollection #271

bramcordie opened this issue Apr 9, 2021 · 0 comments

Comments

@bramcordie
Copy link

bramcordie commented Apr 9, 2021

I have a Custom collection class that extends Doctrine ArrayCollection, which has template annotations out of the box.

The ArrayCollection class has a filter method which I call from my custom collection to create a new collection instance with some items removed. When I try to set the return type for the function, that calls the original filter method, in my custom collection class to self I get a PHPStan error telling me the return type should be ArrayCollection and not an instance of my custom collection.

When I remove the @psalm-return static<TKey,T> annotation from the filter method things work as I expect.

Psalm does not seem bothered about it but maybe it was left over after fixing: #201?

If it is intentional and needed for Psalm, how do I deal with integrating this third party code in my own project running both Psalm and PHPStan? I know there's a bunch of workarounds I can do in the custom Collection class but I have multiple of those in my actual project.

I made a simplified versions of both the ArrayCollection and the custom class:
https://phpstan.org/r/7d36bc06-b81b-45c4-9f63-38dfaa0c5458
https://psalm.dev/r/6de8f68943

So even if Psalm does not complain in the actual project, the same @psalm-return static<TKey,T> annotation is causing problems in the link above.

I already started a discussion at PHPStan and their conclusion is that @resturn static should be sufficient, see: phpstan/phpstan#4825

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

No branches or pull requests

1 participant