RangeFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 21
ccs 9
cts 9
cp 1
crap 3
rs 9.9332
1
<?php
2
3
namespace JBen87\ParsleyBundle\Constraint\Factory;
4
5
use JBen87\ParsleyBundle\Constraint\Constraint;
6
use JBen87\ParsleyBundle\Constraint\Constraints as ParsleyAssert;
7
use Symfony\Component\Validator\Constraint as SymfonyConstraint;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
class RangeFactory implements TranslatableFactoryInterface
11
{
12
    use FactoryTrait;
13
14
    /**
15
     * @inheritdoc
16
     */
17 1
    public function create(SymfonyConstraint $constraint): Constraint
18
    {
19
        /** @var Assert\Range $constraint */
20
21 1
        $options = [];
22
23 1
        if (null !== $constraint->min) {
24
            $options += [
25 1
                'min' => $constraint->min,
26 1
                'minMessage' => $this->trans($constraint->minMessage, ['{{ limit }}' => $constraint->min]),
27
            ];
28
        }
29
30 1
        if (null !== $constraint->max) {
31
            $options += [
32 1
                'max' => $constraint->max,
33 1
                'maxMessage' => $this->trans($constraint->maxMessage, ['{{ limit }}' => $constraint->max]),
34
            ];
35
        }
36
37 1
        return new ParsleyAssert\Range($options);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 1
    public function supports(SymfonyConstraint $constraint): bool
44
    {
45 1
        return $constraint instanceof Assert\Range;
46
    }
47
}
48