Skip to content

Commit

Permalink
Update package to work in PHP8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Oct 17, 2023
1 parent 1bf4ad8 commit 0589212
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/Storage/TimeToLive.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use DateTimeInterface;
use InvalidArgumentException;
use Stringable;
use Throwable;
use function filter_var;
use const FILTER_VALIDATE_INT;

Expand All @@ -19,13 +20,26 @@ final class TimeToLive
{
public static function fromDurationString(string $duration): DateInterval
{
set_error_handler(fn () => true);
$interval = DateInterval::createFromDateString($duration);
restore_error_handler();
if (!$interval instanceof DateInterval) {
throw new InvalidArgumentException(
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.'
);
try {
set_error_handler(fn () => true);
$interval = DateInterval::createFromDateString($duration);
restore_error_handler();
if (!$interval instanceof DateInterval) {
throw new InvalidArgumentException(
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.'
);
}

} catch (Throwable $exception) {
if (!$exception instanceof InvalidArgumentException) {
throw new InvalidArgumentException(
'The ttl value "'.$duration.'" can not be parsable by `DateInterval::createFromDateString`.',
0,
$exception
);
}

throw $exception;
}

return $interval;
Expand Down

0 comments on commit 0589212

Please sign in to comment.