-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RateLimiter] handle error results of DateTime::modify() #58791
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
Conversation
|
||
return $now->diff($now->modify('+'.$interval)); |
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.
modify()
returns false
on failure, thus we must not pass it to diff()
before checking the type
throw $e; | ||
} | ||
try { | ||
$nowPlusInterval = @$now->modify('+' . $interval); |
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.
up to PHP 8.2 the method emitted a warning on invalid intervals which we need to silence here
} | ||
try { | ||
$nowPlusInterval = @$now->modify('+' . $interval); | ||
} catch (\DateMalformedStringException $e) { |
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.
from PHP 8.3 on a DateMalformedStringException
is thrown instead
7236182
to
d526677
Compare
Depending on the version of PHP the modify() method will either throw an exception or issue a warning.
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.
Are there other places where this could be applicable? Or maybe this is the only place in the code relevant?
The other calls of |
Depending on the version of PHP the
modify()
method will either throw an exception or issue a warning.