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 % |
Changes | 0 |
1 | <?php |
||
36 | public function validate($input): bool |
||
37 | { |
||
38 | if (!preg_match('/^[A-Z0-9]{9}$/', $input)) { |
||
39 | return false; |
||
40 | } |
||
41 | |||
42 | $weights = [7, 3, 1, 0, 7, 3, 1, 7, 3]; |
||
43 | $weightedSum = 0; |
||
44 | for ($i = 0; $i < 9; ++$i) { |
||
45 | $code = ord($input[$i]); |
||
46 | if ($i < 3 && $code <= self::ASCII_CODE_9) { |
||
47 | return false; |
||
48 | } |
||
49 | |||
50 | if ($i > 2 && $code >= self::ASCII_CODE_A) { |
||
51 | return false; |
||
52 | } |
||
53 | |||
54 | $difference = $code <= self::ASCII_CODE_9 ? self::ASCII_CODE_0 : self::ASCII_CODE_7; |
||
55 | $weightedSum += ($code - $difference) * $weights[$i]; |
||
56 | } |
||
57 | |||
58 | return $weightedSum % 10 == $input[3]; |
||
59 | } |
||
61 |