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