Passed
Push — master ( 1faf78...54b905 )
by Thanos
03:17
created

KadValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

1 Method

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