Completed
Push — develop ( 0660be...71868c )
by Freddie
04:14
created

RangeConstraintValidator::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 1
rs 9.9666
1
<?php
2
3
namespace FlexPHP\Schema\Validators\Constraints;
4
5
use Symfony\Component\Validator\Constraints\Collection;
6
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
7
use Symfony\Component\Validator\Constraints\NotBlank;
8
use Symfony\Component\Validator\Constraints\Positive;
9
use Symfony\Component\Validator\Constraints\PositiveOrZero;
10
use Symfony\Component\Validator\ConstraintViolationListInterface;
11
use Symfony\Component\Validator\Validation;
12
13
/**
14
 * @Annotation
15
 */
16
class RangeConstraintValidator
17
{
18 9
    public function validate(array $rule): ConstraintViolationListInterface
19
    {
20 9
        $validator = Validation::createValidator();
21
22 9
        return $validator->validate($rule, new Collection([
23
            'min' => [
24 9
                new NotBlank(),
25 9
                new PositiveOrZero(),
26
            ],
27
            'max' => [
28 9
                new NotBlank(),
29 9
                new Positive(),
30 9
                new GreaterThanOrEqual($rule['min'] ?? 0),
31
            ],
32
        ]));
33
    }
34
}
35