Type   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
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 33
ccs 6
cts 6
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 0 3 1
A getValue() 0 7 2
1
<?php
2
3
namespace JBen87\ParsleyBundle\Constraint\Constraints;
4
5
use JBen87\ParsleyBundle\Constraint\Constraint;
6
use JBen87\ParsleyBundle\Exception\ConstraintException;
7
8
abstract class Type extends Constraint
9
{
10
    const TYPES = [
11
        'email' => 'email',
12
        'integer' => 'integer',
13
        'number' => 'number',
14
        'url' => 'url',
15
    ];
16
17
    /**
18
     * @inheritdoc
19
     */
20 5
    protected function getAttribute(): string
21
    {
22 5
        return 'data-parsley-type';
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 5
    protected function getValue(): string
29
    {
30 5
        if (false === in_array($this->getType(), static::TYPES)) {
31 1
            throw ConstraintException::createInvalidValueException();
32
        }
33
34 4
        return $this->getType();
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    abstract protected function getType(): string;
41
}
42