From 6a40baa4dce7507b0e377d8ea5495ade3562f483 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Tue, 3 Dec 2024 06:43:41 +0100 Subject: [PATCH] Simplify Value validation --- src/Value.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Value.php b/src/Value.php index e2b409c..2219ac7 100644 --- a/src/Value.php +++ b/src/Value.php @@ -42,25 +42,14 @@ public function __construct(Item|Token|Bytes|DisplayString|DateTimeInterface|int $value instanceof DisplayString => [$value, $value->type()], false === $value, $value => [$value, Type::Boolean], - $value instanceof DateTimeInterface => [self::filterDate($value), Type::Date], + $value instanceof DateTimeInterface => [ + !$value instanceof DateTimeImmutable ? DateTimeImmutable::createFromInterface($value) : $value, + Type::fromVariable($value), + ], default => [$value, Type::fromVariable($value)], }; } - /** - * Filter a date according to draft-ietf-httpbis-sfbis-latest. - * - * @see https://httpwg.org/http-extensions/draft-ietf-httpbis-sfbis.html#section-3.3.7 - */ - private static function filterDate(DateTimeInterface $value): DateTimeImmutable - { - return match (true) { - !Type::Integer->supports($value->getTimestamp()) => throw new SyntaxError('Date timestamp are limited to 15 digits.'), - !$value instanceof DateTimeImmutable => DateTimeImmutable::createFromInterface($value), - default => $value, - }; - } - /** * Returns a new instance from an encoded byte sequence and an iterable of key-value parameters. */