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
Infer types based on psalm-flow #7773
Comments
I found these snippets: https://psalm.dev/r/78576f9081<?php // --taint-analysis
/**
* @param string $value
* @psalm-flow ($value) -> return
*
*/
function doThis(string $value, bool $isSecure = false): string {
return $value;
}
if (doThis($s) != '') {
echo $s; // should be considered non-empty-string
}
if (doThis($s) !== '') {
echo $s; // should be considered non-empty-string
}
if (doThis($s)) {
echo $s; // should be considered non-empty-string
}
|
The flow annotation only tells that any taint coming in is going out, but you have no idea what the function does. It could completely transform the string (like truncate it or concatenate it). You can't deduce anything about the format of the output based on the input nor the other way around |
Edit: And orklah beat me to it 😛 |
When a function defines
@psalm-flow
And the return-type is known, couldn‘t this information be utilized to specifiy/narrow the type of the parameter, which flows thru the function.see https://psalm.dev/r/78576f9081 which shows the idea applied to strings.
It would work the same way for non-empty-array etc. - I guess.
This idea was born, as I was filling a similar but more concrete use-case for phpstan:
phpstan/phpstan#6792
The text was updated successfully, but these errors were encountered: