Skip to content

Commit

Permalink
Sync implementation with http-structured-field package update
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 2, 2024
1 parent 9c0bc09 commit 1425e79
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Bakame\Http\StructuredFields\Validation\ParametersValidator;

/**
* @phpstan-import-type SfParameterNameRule from ParametersValidator
* @phpstan-import-type SfParameterKeyRule from ParametersValidator
*/
enum Properties: string
{
Expand All @@ -27,7 +27,7 @@ public static function validator(): ParametersValidator
static $validator;

if (null === $validator) {
/** @var array<string, SfParameterNameRule> $filters */
/** @var array<string, SfParameterKeyRule> $filters */
$filters = array_reduce(
self::cases(),
fn (array $rules, self $property): array => [...$rules, ...[$property->value => $property->validate()]],
Expand All @@ -36,27 +36,27 @@ public static function validator(): ParametersValidator

$validator = ParametersValidator::new()
->filterByCriteria(function (Parameters $parameters): bool|string {
if (!$parameters->allowedNames(array_map(fn (self $case) => $case->value, self::cases()))) {
if (!$parameters->allowedKeys(array_map(fn (self $case) => $case->value, self::cases()))) {
return 'The cache contains invalid parameters.';
}

$hit = !in_array($parameters->valueByName(self::Hit->value, default: false), [null, false], true);
$fwd = $parameters->valueByName(self::Forward->value);
$hit = !in_array($parameters->valueByKey(self::Hit->value, default: false), [null, false], true);
$fwd = $parameters->valueByKey(self::Forward->value);

return match (true) {
!$hit && null !== $fwd,
$hit && null === $fwd => true,
default => "The '".self::Hit->value."' and '".self::Forward->value."' parameters are mutually exclusive.",
};
})
->filterByNames($filters);
->filterByKeys($filters);
}

return $validator;
}

/**
* @return SfParameterNameRule
* @return SfParameterKeyRule
*/
public function validate(): array
{
Expand Down

0 comments on commit 1425e79

Please sign in to comment.