mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
Since we have the ability to use `not` as a prefix, having rules that start with not becomes a bit inflexible, verbose, and harder to understand. This commit will refactor the `NotUndef` rule by inverting its behaviour and renaming it to `Undef`.
31 lines
699 B
PHP
31 lines
699 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\Helpers\CanValidateUndefined;
|
|
use Respect\Validation\Message\Template;
|
|
use Respect\Validation\Result;
|
|
use Respect\Validation\Rule;
|
|
|
|
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
|
|
#[Template(
|
|
'{{subject}} must be undefined',
|
|
'{{subject}} must be defined',
|
|
)]
|
|
final class Undef implements Rule
|
|
{
|
|
use CanValidateUndefined;
|
|
|
|
public function evaluate(mixed $input): Result
|
|
{
|
|
return Result::of($this->isUndefined($input), $input, $this);
|
|
}
|
|
}
|