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 | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
34 | public function validate($input): bool |
||
35 | { |
||
36 | if (!is_scalar($input)) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | if (!preg_match('/^\d{10}$/', (string) $input)) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]; |
||
45 | $digits = array_map('intval', str_split($input)); |
||
46 | |||
47 | $targetControlNumber = $digits[9]; |
||
48 | $calculateControlNumber = 0; |
||
49 | |||
50 | for ($i = 0; $i < 9; ++$i) { |
||
51 | $calculateControlNumber += $digits[$i] * $weights[$i]; |
||
52 | } |
||
53 | |||
54 | $calculateControlNumber = $calculateControlNumber % 11; |
||
55 | |||
56 | return $targetControlNumber == $calculateControlNumber; |
||
57 | } |
||
59 |