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 | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 9 |
Changes | 0 |
1 | <?php |
||
16 | 27 | public function validate($input) |
|
17 | { |
||
18 | // Code ported from jsfromhell.com |
||
19 | 27 | $c = preg_replace('/\D/', '', $input); |
|
20 | |||
21 | 27 | if (strlen($c) != 11 || preg_match("/^{$c[0]}{11}$/", $c)) { |
|
22 | 10 | return false; |
|
23 | } |
||
24 | |||
25 | 17 | for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
26 | |||
27 | 17 | if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
28 | 4 | return false; |
|
29 | } |
||
30 | |||
31 | 13 | for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
32 | |||
33 | 13 | if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
34 | 3 | return false; |
|
35 | } |
||
36 | |||
37 | 10 | return true; |
|
38 | } |
||
39 | } |
||
40 |