Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
15 | public static function validate($value) |
||
16 | { |
||
17 | if (strlen($value) !== 7) { |
||
18 | return false; |
||
19 | } |
||
20 | |||
21 | $char6 = substr($value, 0, 6); |
||
22 | |||
23 | if (!preg_match('/^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}$/', $char6)) { |
||
24 | return false; |
||
25 | } |
||
26 | |||
27 | $weight = [1, 3, 1, 7, 3, 9, 1]; |
||
28 | $sum = 0; |
||
29 | for ($i = 0; $i < 6; ++$i) { |
||
30 | $sum += $weight[$i] * intval($char6[$i], 36); |
||
31 | } |
||
32 | $check = (10 - $sum % 10) % 10; |
||
33 | |||
34 | return $value === $char6 . $check; |
||
35 | } |
||
36 | } |
||
37 |