Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Latest commit

 

History

History
76 lines (65 loc) · 1.21 KB

NumericConstraint.md

File metadata and controls

76 lines (65 loc) · 1.21 KB

NumericConstraint

<?php

use Chubbyphp\Validation\Constraint\NumericConstraint;
use Chubbyphp\Validation\ValidatorContextInterface;

$constraint = new NumericConstraint();

/** @var ValidatorContextInterface $context */
$context = ...;

// Use NotNullConstraint to prevent null
$errors = $constraint->validate(
    'path.to.property',
    null,
    $context
);
// [];

// Use NotBlankConstraint to prevent ''
$errors = $constraint->validate(
    'path.to.property',
    '',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    1,
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    1.1,
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    '1.1',
    $context
);
// [];

$errors = $constraint->validate(
    'path.to.property',
    [],
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.numeric.invalidtype',
//         ['type' => 'array']
//     )
// ];

$errors = $constraint->validate(
    'path.to.property',
    'email',
    $context
);
// [
//     new Error(
//         'path.to.property',
//         'constraint.numeric.notnumeric',
//         ['value' => 'email']
//     )
// ];