mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
I identified a pattern among rules that create results with adjacent results, so I created a method that abstracts that. I did have to compromise with the DateTimeDiff, having to escape the input instead of using the name itself, but that seems like a good trade-off. I've also renamed "Subsequent" to "Adjacent" because it sounded better. This is the second time I've renamed this concept, and I hope it will be the last.
28 lines
724 B
PHP
28 lines
724 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use Attribute;
|
|
use Respect\Validation\Message\Template;
|
|
use Respect\Validation\Result;
|
|
use Respect\Validation\Rules\Core\FilteredNonEmptyArray;
|
|
|
|
use function min;
|
|
|
|
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
|
#[Template('The minimum of', 'The minimum of')]
|
|
final class Min extends FilteredNonEmptyArray
|
|
{
|
|
/** @param non-empty-array<mixed> $input */
|
|
protected function evaluateNonEmptyArray(array $input): Result
|
|
{
|
|
return Result::fromAdjacent($input, 'min', $this, $this->rule->evaluate(min($input)));
|
|
}
|
|
}
|