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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
InputBag::get()
should be smarter
#177
Comments
Symfony is really confusing here. This change was triggered by symfony/symfony@381a0a1 - I guess we'd have to make InputBag generic and differentiate between POST and other uses... But I'm not fluent in Symfony enough to know all the places where InputBag can be retrieved from to mark them correctly. |
We recently upgraded from
|
I agree - it should look at the second parameter to |
@benr77 I disagree. You can have |
@ondrejmirtes OK good point you are correct. The problem remains though - how do we get around all these false positives? Is there a workaround or is just ignoring them for the moment the best solution? Thanks |
See #177 (comment) - if someones compiles a list of all possible places to get |
Well In the 5.1.0 changelog there is:
Based on this, can we assume |
This commit shows that the intended message is "non-scalar" values, not "non-string" values: symfony/symfony@381a0a1 I'm asking how a |
Do you mean:
https://symfony.com/doc/current/components/http_foundation.html#accessing-request-data |
Two more questions:
|
|
Alright, so my plan is to introduce some stubs that make InputBag generic, and then to typehint those Request properties properly. |
Generic Anyone could theoretically replace their It'd done by replacing the (until then empty) Symfony doesn't have any built-in mechanism to do so, it's up to the developer to do it manually or use packages like https://github.com/symfony-bundles/json-request-bundle or https://github.com/qandidate-labs/symfony-json-request-transformer. There is also |
@vhenzl So is this fine or incorrect? What would you do? /**
* Request body parameters ($_POST).
*
* @var InputBag<string|int|float|bool>
*/
public $request; |
Please test this before I release it: 95d9ae7 (you'll need phpstan/phpstan dev-master too) |
Fine. It should be a sensible default for most people I believe. I have just realised that So the use case for Having |
Thanks, @ondrejmirtes! I tried it and it works as expected for me. Needless to say, though, that we have just a few places with |
I just tested it too and it seems to be working well. I would be happy for you to release. Thanks for your efforts! |
Awesome :) I'm gonna release it along with PHPStan 0.12.97 in the coming days. |
The solution does not seem right to me. See 95d9ae7#r56194881
|
@Tobion When do you think it doesn't return a string? |
The setter accepts any scalar. So the getter can also return any scalar. |
@Tobion Do you have a use-case where you're setting values to an InputBag that you've got from Request through one of the public properties? Please open a new issue about that. |
I don't know. But if it doesn't make sense, it shouldn't be like this in Symfony. It was changed recently to better support static analysis, but apparently it didn't make it better then if there are still workarounds needed. |
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. |
While technically correct, the change in 716a70d leads to false positive reports for code like this:
AFAIK Symfony never converts query string values from
string
to other types. So unless the$defaultValue
argument is specified,InputBag::get()
always returnsstring|null
. And if$defaultValue
is specified, the return type should bestring|T
whereT
extendsstring|int|float|bool|null
.The text was updated successfully, but these errors were encountered: