phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

RoundFunctionReturnTypeExtension supports types with ConstantScalar

Open Shio3001 opened this issue 1 year ago • 2 comments

Returns a constant when $num parameter and option of the round function are constants.

In this case , the conventional type is returned.

  • $num parameter is a numeric string.
  • $num parameter union contains a numeric string.
  • round() option is not a constant.

Shio3001 avatar Aug 26 '24 03:08 Shio3001

which problem does this change solve? whats your real world use-case?

staabm avatar Aug 26 '24 06:08 staabm

@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

zonuexe avatar Aug 26 '24 10:08 zonuexe