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

ReadableCollection filter method with phpstan in the context of a Collection instancied as ArrayCollection #364

Open
Sinjonathan opened this issue Feb 21, 2023 · 0 comments

Comments

@Sinjonathan
Copy link

Sinjonathan commented Feb 21, 2023

HI,

I report here my problem after being redirected by phpstan, see issue here : #phpstan/phpstan-doctrine#428

Seem like filter method docbloc is missconfigured or something alike between Collection/ReadableCollection.

With doctrine/collections 2.1.2 and phpstan/phpstan-doctrine 1.3.32 i get a phpstan error on a valid code before update (1.7.2 => 2.1.2)

Here a phpstan playground to expose how we process to get the error : playground

We get :

Method Test::getFiltered() should return Collection<int, int> but returns ReadableCollection<int, int>.

I can avoid the error by adding this in Collection interface but I'm not sure that it is logical with your choice of create a ReadableCollection interface.

   /**
     * {@inheritDoc}
     *
     * @return static
     * @psalm-return static<TKey,T>
     */
    public function filter(Closure $p);

If it's not the solution, how can I manage to avoid the error in the context of a collection instancied as ArrayCollection that we would filter ? What is the best approach ?

Thank for your time

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