We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 4 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | 10 | private function isLuhn($input): bool |
|
| 34 | { |
||
| 35 | 10 | $sum = 0; |
|
| 36 | 10 | $numDigits = mb_strlen($input); |
|
| 37 | 10 | $parity = $numDigits % 2; |
|
| 38 | 10 | for ($i = 0; $i < $numDigits; ++$i) { |
|
| 39 | 10 | $digit = mb_substr($input, $i, 1); |
|
| 40 | 10 | if ($parity == ($i % 2)) { |
|
| 41 | 10 | $digit <<= 1; |
|
| 42 | 10 | if (9 < $digit) { |
|
| 43 | 6 | $digit = $digit - 9; |
|
| 44 | } |
||
| 45 | } |
||
| 46 | 10 | $sum += $digit; |
|
| 47 | } |
||
| 48 | |||
| 49 | 10 | return 0 == ($sum % 10); |
|
| 50 | } |
||
| 52 |