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 | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 8.0189 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 7 | public function validate($input) |
|
| 24 | { |
||
| 25 | 7 | if (!preg_match('/^[A-Z0-9]{9}$/', $input)) { |
|
| 26 | 1 | return false; |
|
| 27 | } |
||
| 28 | |||
| 29 | 6 | $weights = [7, 3, 1, 0, 7, 3, 1, 7, 3]; |
|
| 30 | 6 | $weightedSum = 0; |
|
| 31 | 6 | for ($i = 0; $i < 9; ++$i) { |
|
| 32 | 6 | $code = ord($input[$i]); |
|
| 33 | 6 | if ($i < 3 && $code <= 57) { // 57 is "9" |
|
| 34 | return false; |
||
| 35 | } |
||
| 36 | |||
| 37 | 6 | if ($i > 2 && $code >= 65) { // 65 is "A" |
|
| 38 | 1 | return false; |
|
| 39 | } |
||
| 40 | |||
| 41 | 6 | $difference = $code <= 57 ? 48 : 55; // 48 is "0" |
|
| 42 | 6 | $weightedSum += ($code - $difference) * $weights[$i]; |
|
| 43 | 6 | } |
|
| 44 | |||
| 45 | 5 | return $weightedSum % 10 == $input[3]; |
|
| 46 | } |
||
| 47 | } |
||
| 48 |