We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 8 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 8.0231 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 12 | public function isValid($input): bool |
|
| 26 | { |
||
| 27 | 12 | if (!preg_match('/^[A-Z0-9]{9}$/', $input)) { |
|
| 28 | 1 | return false; |
|
| 29 | } |
||
| 30 | |||
| 31 | 11 | $weights = [7, 3, 1, 0, 7, 3, 1, 7, 3]; |
|
| 32 | 11 | $weightedSum = 0; |
|
| 33 | 11 | for ($i = 0; $i < 9; ++$i) { |
|
| 34 | 11 | $code = ord($input[$i]); |
|
| 35 | 11 | if ($i < 3 && $code <= 57) { // 57 is "9" |
|
| 36 | return false; |
||
| 37 | } |
||
| 38 | |||
| 39 | 11 | if ($i > 2 && $code >= 65) { // 65 is "A" |
|
| 40 | 1 | return false; |
|
| 41 | } |
||
| 42 | |||
| 43 | 11 | $difference = $code <= 57 ? 48 : 55; // 48 is "0" |
|
| 44 | 11 | $weightedSum += ($code - $difference) * $weights[$i]; |
|
| 45 | } |
||
| 46 | |||
| 47 | 10 | return $weightedSum % 10 == $input[3]; |
|
| 48 | } |
||
| 50 |