phpstan / phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
MIT License
100 stars 35 forks source link

Update ComponentModel\Container stub for component-model 3.1.0 #142

Open jtojnar opened 3 months ago

jtojnar commented 3 months ago

That version changes the return type to array when $deep argument is false (default): https://github.com/nette/component-model/commit/7f613eed7f5e57b6bde2d0be1bfdbb7e161620b3

It also deprecates the arguments but we cannot add deprecated annotation to those. https://github.com/nette/component-model/commit/4e0946a788b4ac42ea903b761c693ec7dd083a69

jtojnar commented 3 months ago

It also deprecates the arguments but we cannot add deprecated annotation to those.

There is no @param-deprecated annotation AFAICT and the upcoming #[Deprecated] attribute RFC leaves it up for future.

jtojnar commented 3 months ago

Looks like this is recognized properly, as I no longer get

  173    Parameter #1 $array of function array_filter expects array, Iterator<int|string, Nette\ComponentModel\IComponent> given.  

But for some reason it now thinks it returns the union of both branches:

  173    Parameter #1 $array of function array_filter expects array, array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> given.  

(This is with PHPStan 1.11.1.)

jtojnar commented 3 months ago

I tried to reproduce it in Playground but it does not fail there: https://phpstan.org/r/50c723fc-6a84-4ca3-945d-fdc4fc5f9fbc

Possibly this is some difference in how stubs are handled?