Conditions | 4 |
Paths | 4 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
10 | 10 | public function validate($value, Constraint $constraint) |
|
11 | { |
||
12 | 10 | if (empty($value)) { |
|
13 | 2 | return true; |
|
14 | } |
||
15 | |||
16 | 8 | if (!is_numeric($value)) { |
|
17 | 1 | $this->buildViolation($value, $constraint); |
|
18 | |||
19 | 1 | return false; |
|
20 | } |
||
21 | |||
22 | 7 | $reverseAfm = array_reverse(str_split($value)); |
|
23 | 7 | $lastDigit = (int) array_shift($reverseAfm); |
|
24 | 7 | $checksum = $this->calculateChecksum($reverseAfm); |
|
25 | 7 | $mod = $checksum % 11; |
|
26 | |||
27 | 7 | if ($this->checkModAgainstLastDigit($mod, $lastDigit)) { |
|
28 | 6 | return true; |
|
29 | } |
||
30 | |||
31 | 1 | $this->buildViolation($value, $constraint); |
|
32 | |||
33 | 1 | return false; |
|
34 | } |
||
35 | |||
57 | } |