Conditions | 7 |
Paths | 6 |
Total Lines | 29 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 7 |
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 | $first = (int) array_shift($reverseAfm); |
|
24 | 7 | $sum = 0; |
|
25 | |||
26 | 7 | foreach ($reverseAfm as $index => $value) { |
|
27 | 7 | $sum += $value * pow(2, ++$index); |
|
28 | } |
||
29 | |||
30 | 7 | $mod = $sum % 11; |
|
31 | 7 | if ((10 === $mod && $first === 0) || ($mod === $first)) { |
|
32 | 6 | return true; |
|
33 | } |
||
34 | |||
35 | 1 | $this->buildViolation($value, $constraint); |
|
36 | |||
37 | 1 | return false; |
|
38 | } |
||
39 | |||
51 | } |