Skip to content

[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

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Nov 6, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues
License MIT

Depending on the version of PHP the modify() method will either throw an exception or issue a warning.


return $now->diff($now->modify('+'.$interval));
Copy link
Member Author

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);
Copy link
Member Author

@xabbuh xabbuh Nov 7, 2024

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) {
Copy link
Member Author

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

@xabbuh xabbuh force-pushed the pr-58757 branch 2 times, most recently from 7236182 to d526677 Compare November 7, 2024 10:12
Depending on the version of PHP the modify() method will either throw an
exception or issue a warning.
Copy link
Member

@alexandre-daubois alexandre-daubois left a 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?

@xabbuh
Copy link
Member Author

xabbuh commented Nov 7, 2024

The other calls of modify() look safe to me.

@xabbuh xabbuh merged commit da4eb8b into symfony:5.4 Nov 8, 2024
11 of 12 checks passed
@xabbuh xabbuh deleted the pr-58757 branch November 8, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants