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
Add support for integer ranges in strtotime() with constant strings #1045
Conversation
dac1c88
to
a1fb11d
Compare
|
||
$results = array_map('intval', $results); | ||
|
||
return IntegerRangeType::createAllGreaterThan(min($results)); |
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.
This yields:
57 Parameter #1 $value of static method
PHPStan\Type\IntegerRangeType::createAllGreaterThan() expects
float|int, int|false given.
But I don't get it, because $results is not empty, and so min() cannot return false.
Edit: fixed with a (int)
cast for now.. but not pleased :)
$strtotimeNegativeInt = strtotime('1969-12-31 12:00:00 UTC'); | ||
assertType('int<-43199, max>', $strtotimeNegativeInt); |
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.
could the min value depend on the systems time-zone?
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.
Yes it does. I think it's mostly ok as the main point is to know if it's positive-int or int IMO. negative-int in dates are pretty rare.. The high precision requires you have a correctly set timezone, which sounds like an OK limitation to me but maybe it isnt?
assertType('int|false', $strtotimeCrash); | ||
|
||
$strtotimeWithBase = strtotime('+2 days', time()); | ||
assertType('int', $strtotimeWithBase); |
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.
maybe
assertType('int', $strtotimeWithBase); | |
assertType('positive-int', $strtotimeWithBase); |
?
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.
Yes but that would require parsing the second argument properly, which I am not doing right now. Feel free to send a PR for that, it's beyond my skills here :D
3d0c903
to
ca5e927
Compare
ba41785
to
494a7f8
Compare
… unable to cause a false return
Thank you! |
I migrated the existing tests from legacy tests, I hope this makes sense.
I am trying to pass strtotime() to a
positive-int
param and figured this should just work :)The ranges are always
int<$oldestResolvedTime, max>
as time flows forward, the result may increase but should not decrease.