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 % |
| Tests | 13 |
| CRAP Score | 5.009 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | 8 | public function validate($input) |
|
| 23 | { |
||
| 24 | 8 | if (!(new Digit())->validate($input)) { |
|
| 25 | return false; |
||
| 26 | } |
||
| 27 | |||
| 28 | 8 | $sum = 0; |
|
| 29 | 8 | $numDigits = strlen($input); |
|
| 30 | 8 | $parity = $numDigits % 2; |
|
| 31 | 8 | for ($i = 0; $i < $numDigits; $i++) { |
|
| 32 | 8 | $digit = substr($input, $i, 1); |
|
| 33 | 8 | if ($parity == ($i % 2)) { |
|
| 34 | 8 | $digit <<= 1; |
|
| 35 | 8 | if (9 < $digit) { |
|
| 36 | 4 | $digit = $digit - 9; |
|
| 37 | } |
||
| 38 | } |
||
| 39 | 8 | $sum += $digit; |
|
| 40 | } |
||
| 41 | |||
| 42 | 8 | return (0 == ($sum % 10)); |
|
| 43 | } |
||
| 44 | } |
||
| 45 |