Description
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