Skip to content

Commit

Permalink
fix phpstan reports
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 5, 2024
1 parent dcceba4 commit a9d1209
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
};
}
}

0 comments on commit a9d1209

Please sign in to comment.