mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
Update the validation engine of the "NotOptional" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
8805c88d4c
commit
c198547a17
|
@ -11,6 +11,8 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Helpers\CanValidateUndefined;
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rules\Core\Standard;
|
||||
|
||||
#[Template(
|
||||
'The value must not be optional',
|
||||
|
@ -22,23 +24,20 @@ use Respect\Validation\Message\Template;
|
|||
'{{name}} must be optional',
|
||||
self::TEMPLATE_NAMED,
|
||||
)]
|
||||
final class NotOptional extends AbstractRule
|
||||
final class NotOptional extends Standard
|
||||
{
|
||||
use CanValidateUndefined;
|
||||
|
||||
public const TEMPLATE_NAMED = '__named__';
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
return $this->isUndefined($input) === false;
|
||||
}
|
||||
|
||||
protected function getStandardTemplate(mixed $input): string
|
||||
{
|
||||
if ($input || $this->getName()) {
|
||||
return self::TEMPLATE_NAMED;
|
||||
}
|
||||
|
||||
return self::TEMPLATE_STANDARD;
|
||||
return new Result(
|
||||
$this->isUndefined($input) === false,
|
||||
$input,
|
||||
$this,
|
||||
[],
|
||||
($input || $this->getName() ? self::TEMPLATE_NAMED : self::TEMPLATE_STANDARD)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue