Conditions | 4 |
Paths | 4 |
Total Lines | 28 |
Code Lines | 15 |
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) != 11) { |
||
27 | $this->violations[] = 'length'; |
||
28 | |||
29 | return false; |
||
30 | } |
||
31 | |||
32 | $factor = range(9, 1); |
||
33 | $index = 0; |
||
34 | $checksum = 0; |
||
35 | |||
36 | while ($index <= 8) { |
||
37 | $checksum = $checksum + intval($input[$index]) + $factor[$index]; |
||
38 | $index++; |
||
39 | } |
||
40 | |||
41 | $value = $checksum % 101; |
||
42 | |||
43 | return substr($input, 9, 2) == $value; |
||
44 | } |
||
46 |