Length::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace JBen87\ParsleyBundle\Constraint\Constraints;
4
5
use JBen87\ParsleyBundle\Constraint\Constraint;
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
class Length extends Constraint
9
{
10
    /**
11
     * @var int
12
     */
13
    private $min;
14
15
    /**
16
     * @var int
17
     */
18
    private $max;
19
20
    /**
21
     * @param array $options
22
     */
23 5
    public function __construct(array $options = [])
24
    {
25 5
        parent::__construct($options);
26
27 3
        $this->min = $options['min'];
28 3
        $this->max = $options['max'];
29 3
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 1
    protected function getAttribute(): string
35
    {
36 1
        return 'data-parsley-length';
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 1
    protected function getValue(): string
43
    {
44 1
        return sprintf('[%d, %d]', $this->min, $this->max);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 5
    protected function configureOptions(OptionsResolver $resolver): void
51
    {
52
        $resolver
53 5
            ->setRequired(['min', 'max'])
54 5
            ->setAllowedTypes('min', ['int'])
55 5
            ->setAllowedTypes('max', ['int'])
56
        ;
57 5
    }
58
}
59