Conditions | 6 |
Paths | 5 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 6.0163 |
Changes | 0 |
1 | <?php |
||
11 | 21 | public function validate($value, Constraint $constraint) |
|
12 | { |
||
13 | 21 | if (!$constraint instanceof Amka) { |
|
14 | throw new UnexpectedTypeException($constraint, Amka::class); |
||
15 | } |
||
16 | |||
17 | 21 | if (empty($value)) { |
|
18 | 2 | return; |
|
19 | } |
||
20 | |||
21 | 19 | if (!preg_match('/^[0-9]{11}$/', $value) || $value === '00000000000') { |
|
22 | 3 | $this->buildViolation($value, $constraint); |
|
23 | 3 | return; |
|
24 | } |
||
25 | |||
26 | 16 | $checksum = $this->calculateChecksum($value); |
|
27 | |||
28 | 16 | if ($checksum % 10 !== 0) { |
|
29 | 2 | $this->buildViolation($value, $constraint); |
|
30 | 2 | return; |
|
31 | } |
||
32 | 14 | } |
|
33 | |||
63 | } |