We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 9 |
Paths | 11 |
Total Lines | 22 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 9.0608 |
Changes | 0 |
1 | <?php |
||
18 | 17 | public function validate($input): bool |
|
19 | { |
||
20 | // Code ported from jsfromhell.com |
||
21 | 17 | $c = preg_replace('/\D/', '', $input); |
|
22 | |||
23 | 17 | if (11 != mb_strlen($c) || preg_match("/^{$c[0]}{11}$/", $c)) { |
|
24 | 10 | return false; |
|
25 | } |
||
26 | |||
27 | 7 | for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
28 | |||
29 | 7 | if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
30 | 4 | return false; |
|
31 | } |
||
32 | |||
33 | 3 | for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
34 | |||
35 | 3 | if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
36 | 3 | return false; |
|
37 | } |
||
38 | |||
39 | return true; |
||
40 | } |
||
42 |