-
Notifications
You must be signed in to change notification settings - Fork 507
Specify return type for filter_input()
#2010
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
Conversation
3c28408
to
41e927e
Compare
This pull request has been marked as ready for review. |
41e927e
to
dade61f
Compare
22740d4
to
ff19000
Compare
This pull request has been marked as ready for review. |
3ca69d1
to
2ec1ef0
Compare
2ec1ef0
to
84d53c7
Compare
do you think we can get that this one in the next release? 😊 it's 90% refactor and would help me get rid of some errors in a legacy app which helps me finish the 7.4 -> 8.x upgrade. at least that's what I was telling myself when I was last procrastinating when working on it :D |
This pull request has been marked as ready for review. |
Fyi the return type in case the array offset does not exist and the force array flag is set is not handled properly. It's a bit tricky and I might need to refactor the helper maybe. Good that you didn't merge it yet 😅 |
4959e62
to
45e9d42
Compare
45e9d42
to
30070eb
Compare
I'm happy with this now, maybe the new method in the helper is useful for #2257 too. |
This pull request has been marked as ready for review. |
23874d7
to
7db3ed6
Compare
$typeExpr = $functionCall->getArgs()[0]->value; | ||
if ( | ||
!($typeExpr instanceof ConstFetch) | ||
|| !in_array((string) $typeExpr->name, ['INPUT_GET', 'INPUT_POST', 'INPUT_COOKIE', 'INPUT_SERVER', 'INPUT_ENV'], true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that this condition only works for literal INPUT_GET
ConstFetch in the code, but doesn't work for @param INPUT_GET|INPUT_POST $abc
from PHPDocs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so rebasing does summon you :D
good point, I also dislike that. I'm not good with constants, do you have any better ideas you can think of? Do I need to resolve them somehow I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this is already a solved problem, FilterFunctionReturnTypeHelper does this with hasFlag
, $this->getConstant()
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that would work I guess, I thought there's a better approach. I'll switch it to use those helpers then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adapted. I could not re-use those methods but found another approach. not sure yet if there's a better one though
can still be made stricter / more correct any time
Thank you! |
Closes phpstan/phpstan#6261
See https://www.php.net/manual/en/function.filter-input.php, the important difference to
filter_var
is the handling of the non-set variables in the superglobal arrays