phpstan-src
phpstan-src copied to clipboard
RoundFunctionReturnTypeExtension supports types with ConstantScalar
Returns a constant when $num parameter and option of the round function are constants.
In this case , the conventional type is returned.
-
$numparameter is a numeric string. -
$numparameter union contains a numeric string. -
round()option is not a constant.
which problem does this change solve? whats your real world use-case?
@staabm
I'm sure there are several use cases for this, but one I quickly spotted in my private code is the following pattern, which uses $last_page for some logic other than just printing it.
Ideally it would be even more useful if a float range type was implemented, but I feel like this is worthwhile enough on its own.
const MAX = 1000;
const PER_PAGE = 30;
$last_page = (int)floor(MAX / PER_PAGE);
https://phpstan.org/r/b583dc30-3b4e-4b1f-af60-713159f43309