We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 5 |
| Paths | 5 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public function validate($input) |
||
| 23 | { |
||
| 24 | if (!(new Digit())->validate($input)) { |
||
| 25 | return false; |
||
| 26 | } |
||
| 27 | |||
| 28 | $sum = 0; |
||
| 29 | $numDigits = strlen($input); |
||
| 30 | $parity = $numDigits % 2; |
||
| 31 | for ($i = 0; $i < $numDigits; $i++) { |
||
| 32 | $digit = substr($input, $i, 1); |
||
| 33 | if ($parity == ($i % 2)) { |
||
| 34 | $digit <<= 1; |
||
| 35 | if (9 < $digit) { |
||
| 36 | $digit = $digit - 9; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | $sum += $digit; |
||
| 40 | } |
||
| 41 | |||
| 42 | return (0 == ($sum % 10)); |
||
| 43 | } |
||
| 44 | } |
||
| 45 |