Conditions | 9 |
Paths | 13 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
15 | public static function validate($cusip) |
||
16 | { |
||
17 | if (9 !== strlen($cusip)) { |
||
18 | return false; |
||
19 | } |
||
20 | $sum = 0; |
||
21 | for ($i = 0; $i <= 7; ++$i) { |
||
22 | $c = $cusip[$i]; |
||
23 | if (ctype_digit($c)) { |
||
24 | $v = intval($c); |
||
25 | } elseif (ctype_alpha($c)) { |
||
26 | $position = ord(strtoupper($c)) - ord('A') + 1; |
||
27 | $v = $position + 9; |
||
28 | } elseif ('*' == $c) { |
||
29 | $v = 36; |
||
30 | } elseif ('@' == $c) { |
||
31 | $v = 37; |
||
32 | } elseif ('#' == $c) { |
||
33 | $v = 38; |
||
34 | } else { |
||
35 | return false; |
||
36 | } |
||
37 | if (1 == $i % 2) { |
||
38 | $v *= 2; |
||
39 | } |
||
40 | $sum += floor($v / 10) + ($v % 10); |
||
41 | } |
||
42 | |||
43 | return ord($cusip[8]) - 48 == (10 - ($sum % 10)) % 10; |
||
44 | } |
||
45 | } |
||
46 |