We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 7 |
Paths | 3 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 7 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6 | 96 | public function validate($input) |
|
7 | { |
||
8 | 96 | $ret = false; |
|
9 | |||
10 | 96 | if ((strlen($input = preg_replace('/[^\d]/', '', $input)) == 11) |
|
11 | 96 | && (str_repeat($input[1], 11) != $input)) { |
|
12 | 48 | $dsc = 0; |
|
13 | 48 | for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) { |
|
14 | 48 | $v += (int) $input[$i] * $j; |
|
15 | 48 | } |
|
16 | |||
17 | 48 | if (($vl1 = $v % 11) >= 10) { |
|
18 | 4 | $vl1 = 0; |
|
19 | 4 | $dsc = 2; |
|
20 | 4 | } |
|
21 | |||
22 | 48 | for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) { |
|
23 | 48 | $v += (int) $input[$i] * $j; |
|
24 | 48 | } |
|
25 | |||
26 | 48 | $vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc; |
|
27 | 48 | $ret = sprintf('%d%d', $vl1, $vl2) == substr($input, -2); |
|
28 | 48 | } |
|
29 | |||
30 | 96 | return $ret; |
|
31 | } |
||
32 | } |
||
33 |