phpstan / phpstan-symfony

Symfony extension for PHPStan
MIT License
698 stars 89 forks source link

Missing array as an available return type for InputBag::get() #357

Closed Steveb-p closed 1 year ago

Steveb-p commented 1 year ago

Hi,

We have a case where we have a method:

QueryValidatorBuilder::validateFilterQueryInput(InputBag $input)

...and we expect to receive data using an URL containing the following query parameter:

?filter[CreatedAt][Value]=abc

This means that the InputBag would contain an array of arrays.

Since InputBag is generic (stub here: https://github.com/phpstan/phpstan-symfony/blob/1.2.x/stubs/Symfony/Component/HttpFoundation/InputBag.stub) we of course receive an analysis error that we need to define what types of data we expect InputBag to contain. However, we cannot specify an array, since it is not declared in the allowed data types for that generic.

Is there any way we could circumvent this issue, other than of course putting it into baseline? Is it maybe possible to drop the scalar data type completely?

ondrejmirtes commented 1 year ago

Hi, it's impossible to receive an array from InputBag because it's guarded by a native return type: https://github.com/symfony/http-foundation/blob/e0ad0d153e1c20069250986cd9e9dd1ccebb0d66/InputBag.php#L28

Maybe it's not the case in your Symfony version but it would definitely be a problem for you in the future so you need to rethink your approach anyway :)

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.