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 |
||
42 | 9 | private function isValid(string $input): bool |
|
43 | { |
||
44 | 9 | $sum = 0; |
|
45 | 9 | $numDigits = mb_strlen($input); |
|
46 | 9 | $parity = $numDigits % 2; |
|
47 | 9 | for ($i = 0; $i < $numDigits; ++$i) { |
|
48 | 9 | $digit = mb_substr($input, $i, 1); |
|
49 | 9 | if ($parity == ($i % 2)) { |
|
50 | 8 | $digit <<= 1; |
|
51 | 8 | if (9 < $digit) { |
|
52 | 6 | $digit = $digit - 9; |
|
53 | } |
||
54 | } |
||
55 | 9 | $sum += $digit; |
|
56 | } |
||
57 | |||
58 | 9 | return 0 == ($sum % 10); |
|
59 | } |
||
61 |