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

RangeConstraintValidator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 13 1
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