Conditions | 6 |
Paths | 10 |
Total Lines | 41 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
16 | public function isValid($input = null) |
||
17 | { |
||
18 | if (!is_numeric($input)) { |
||
19 | $this->violations[] = 'numeric'; |
||
20 | |||
21 | return false; |
||
22 | } |
||
23 | |||
24 | $input = (string) $input; |
||
25 | |||
26 | if (strlen($input) != 8) { |
||
27 | $this->violations[] = 'length'; |
||
28 | |||
29 | return false; |
||
30 | } |
||
31 | |||
32 | $factor1 = range(1, 7); |
||
33 | $factor2 = range(3, 9); |
||
34 | |||
35 | $checksum1 = 0; |
||
36 | $index = 0; |
||
37 | |||
38 | while ($index <= 6) { |
||
39 | $checksum1 = $checksum1 + intval($input[$index]) * $factor1[$index]; |
||
40 | $index++; |
||
41 | } |
||
42 | |||
43 | $value1 = $checksum1 % 11; |
||
44 | |||
45 | $index = 0; |
||
46 | $checksum2 = 0; |
||
47 | |||
48 | while ($index <= 6) { |
||
49 | $checksum2 = $checksum2 + intval($input[$index]) * $factor2[$index]; |
||
50 | $index++; |
||
51 | } |
||
52 | |||
53 | $value2 = $checksum2 % 11; |
||
54 | $check = ($value1 > 9 ? $value2 : $value1); |
||
55 | |||
56 | return $input[7] == $check; |
||
57 | } |
||
59 |