Conditions | 4 |
Paths | 5 |
Total Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public static function check($str) { |
||
29 | |||
30 | $sum = 0; |
||
31 | $length = strlen($str); |
||
32 | $parity = $length % 2; |
||
33 | |||
34 | $sum += substr($str, $length - 1); |
||
35 | |||
36 | for ($i = $length - 2; 0 <= $i; --$i) { |
||
37 | |||
38 | $digit = intval(substr($str, $i, 1)); |
||
39 | |||
40 | if ($parity === $i % 2) { |
||
41 | $digit *= 2; |
||
42 | } |
||
43 | if (9 < $digit) { |
||
44 | $digit -= 9; |
||
45 | } |
||
46 | |||
47 | $sum += $digit; |
||
48 | } |
||
49 | |||
50 | return 0 === $sum % 10; |
||
51 | } |
||
52 | } |
||
53 |