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