| Conditions | 4 |
| Paths | 5 |
| Total Lines | 31 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public static function check($str) { |
||
| 30 | |||
| 31 | // Initialize. |
||
| 32 | $sum = 0; |
||
| 33 | $length = strlen($str); |
||
| 34 | $parity = $length % 2; |
||
| 35 | |||
| 36 | // Get the sum. |
||
| 37 | $sum += substr($str, $length - 1); |
||
| 38 | |||
| 39 | // Handle each character. |
||
| 40 | for ($i = $length - 2; 0 <= $i; --$i) { |
||
| 41 | |||
| 42 | // Get the digit. |
||
| 43 | $digit = intval(substr($str, $i, 1)); |
||
| 44 | |||
| 45 | // Check the parity. |
||
| 46 | if ($parity === $i % 2) { |
||
| 47 | $digit *= 2; |
||
| 48 | } |
||
| 49 | if (9 < $digit) { |
||
| 50 | $digit -= 9; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Add the digit. |
||
| 54 | $sum += $digit; |
||
| 55 | } |
||
| 56 | |||
| 57 | // Return. |
||
| 58 | return 0 === $sum % 10; |
||
| 59 | } |
||
| 60 | |||
| 62 |