0 follower

Final Class Yiisoft\Validator\Rule\Type\FloatTypeHandler

InheritanceYiisoft\Validator\Rule\Type\FloatTypeHandler
ImplementsYiisoft\Validator\RuleHandlerInterface

A handler for {@see FloatType} rule. Validates that the value has float type - {@link https://www.php.net/manual/en/language.types.float.php}.

Method Details

Hide inherited methods

validate() public method

public Yiisoft\Validator\Result validate ( mixed $value, Yiisoft\Validator\RuleInterface $rule, Yiisoft\Validator\ValidationContext $context )
$value mixed
$rule Yiisoft\Validator\RuleInterface
$context Yiisoft\Validator\ValidationContext

                public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
    if (!$rule instanceof FloatType) {
        throw new UnexpectedRuleException(FloatType::class, $rule);
    }
    if (!is_float($value)) {
        return (new Result())->addError($rule->getMessage(), [
            'property' => $context->getTranslatedProperty(),
            'Property' => $context->getCapitalizedTranslatedProperty(),
            'type' => get_debug_type($value),
        ]);
    }
    return new Result();
}