From a9d1209c69b42d56b97f1f35d567c819cd0c3429 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Thu, 5 Dec 2024 12:10:00 +0100 Subject: [PATCH] fix phpstan reports --- src/Properties.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Properties.php b/src/Properties.php index 63e14de..d4876c2 100644 --- a/src/Properties.php +++ b/src/Properties.php @@ -2,10 +2,13 @@ namespace Bakame\Http\CacheStatus; +use Bakame\Http\StructuredFields\Bytes; +use Bakame\Http\StructuredFields\DisplayString; use Bakame\Http\StructuredFields\Parameters; use Bakame\Http\StructuredFields\Token; use Bakame\Http\StructuredFields\Type; use Bakame\Http\StructuredFields\Validation\ParametersValidator; +use DateTimeInterface; use function array_reduce; use function in_array; @@ -67,22 +70,22 @@ public static function validator(): ParametersValidator public function validate(): array { return match ($this) { - self::Hit => ['validate' => fn (mixed $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], - self::TimeToLive => ['validate' => fn (mixed $value): bool|string => is_int($value) ? true : "The '{name}' parameter must be an integer; {value} given."], - self::Key => ['validate' => fn (mixed $value): bool|string => is_string($value) ? true : "The '{name}' parameter must be a string; {value} given."], - self::Detail => ['validate' => fn (mixed $value): bool|string => Type::fromVariable($value)->isOneOf(Type::String, Type::Token) ? true : "The '{name}' parameter must be a string; {value} given."], - self::Forward => ['validate' => fn (mixed $value): bool|string => match (true) { + self::Hit => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], + self::TimeToLive => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => is_int($value) ? true : "The '{name}' parameter must be an integer; {value} given."], + self::Key => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => is_string($value) ? true : "The '{name}' parameter must be a string; {value} given."], + self::Detail => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => Type::fromVariable($value)->isOneOf(Type::String, Type::Token) ? true : "The '{name}' parameter must be a string; {value} given."], + self::Forward => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => match (true) { !$value instanceof Token => "The '{name}' parameter must be a Token; {value} given.", null === ForwardedReason::tryFromToken($value) => "The '{name}' parameter Token value '{value}' is unknown or unsupported.", default => true, }], - self::ForwardStatusCode => ['validate' => fn (mixed $value): bool|string => match (true) { + self::ForwardStatusCode => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => match (true) { !is_int($value) => "The '{name}' parameter must be an integer; {value} given.", $value < 100 || $value > 599 => "The '{name}' parameter value '{value}' must be a valid HTTP status code", default => true, }], - self::Stored => ['validate' => fn (mixed $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], - self::Collapsed => ['validate' => fn (mixed $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], + self::Stored => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], + self::Collapsed => ['validate' => fn (Token|DisplayString|Bytes|DateTimeInterface|int|float|bool|string $value): bool|string => is_bool($value) ? true : "The '{name}' parameter must be a boolean; {value} given.", 'default' => false], }; } }