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

KadValidator::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 9
nc 3
nop 2
crap 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
}