respect-validation/library/Rules/Undef.php
Henrique Moody 7046560f77
Invert the behaviour of NotUndef
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`.
2025-12-27 18:49:46 +01:00

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);
}
}