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 | 11 |
CRAP Score | 9 |
Changes | 0 |
1 | <?php |
||
35 | 28 | public function isValid($input): bool |
|
36 | { |
||
37 | // Code ported from jsfromhell.com |
||
38 | 28 | $c = preg_replace('/\D/', '', $input); |
|
39 | |||
40 | 28 | if (11 != mb_strlen($c) || preg_match("/^{$c[0]}{11}$/", $c)) { |
|
41 | 11 | return false; |
|
42 | } |
||
43 | |||
44 | 18 | for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
45 | |||
46 | 18 | if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
47 | 4 | return false; |
|
48 | } |
||
49 | |||
50 | 14 | for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--); |
|
51 | |||
52 | 14 | if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) { |
|
53 | 3 | return false; |
|
54 | } |
||
55 | |||
56 | 11 | return true; |
|
57 | } |
||
59 |