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
support integer-range type in min/max #627
Conversation
by implement min(x, y) and max(x, y) as ternary
arrays are compared by number of elements
} | ||
} | ||
} | ||
|
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.
Isn't it possible that we could delete some code that's already in the extension thanks to this logic?
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.
the code above only handles the 1-arg case and the code below handles the any-number-of-args case.
I guess we can drop it, after we push the
return $scope->getType(new Ternary(
new Smaller($args[0]->value, $args[1]->value),
$args[1]->value,
$args[0]->value
));
approach into a direction where it supports any number of args (using BooleanAnd
and BooleanOr
) as you suggested in #604 (comment)
but IMO this should be a separate PR
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.
Cool :)
Thank you! |
rewrite
min($x, $y)
as$x < $y ? $x : $y
implemented the integer-range min/max support based on the idea of ondrey in #604 (comment)
closes phpstan/phpstan#5398
this fixes the reported issue, but I can think of more complex scenarios which are not yet covered, e.g.
but I think these should be covered in a separate PR, as they are rare and this PR - as is - already covers a lot of real world code
closes #604