Passed
Push — master ( 7bcc6f...9b4044 )
by Thanos
01:49
created

KadValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 21
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 18 4
1
<?php
2
3
namespace SymfonyGreekValidation;
4
5
use Symfony\Component\Validator\Constraint;
6
use Symfony\Component\Validator\ConstraintValidator;
7
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
8
9
class KadValidator extends ConstraintValidator
10
{
11 12
    public function validate($value, Constraint $constraint)
12
    {
13 12
        if (!$constraint instanceof Kad) {
14
            throw new UnexpectedTypeException($constraint, Kad::class);
15
        }
16
17 12
        if (empty($value)) {
18 2
            return;
19
        }
20
21 10
        if (!preg_match('/^([0-9]{2}\.){3}[0-9]{2}$/', $value)) {
22 5
            $this->context->buildViolation($constraint->message)
23 5
                ->setParameter('{{ string }}', $value)
24 5
                ->addViolation();
25
26 5
            return;
27
        }
28
    }
29
}