Conditions | 8 |
Paths | 7 |
Total Lines | 31 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
31 | public static function is_valid($id_document_number = null, $id_type = null) { |
||
32 | if (is_null($id_document_number)) { |
||
33 | throw new \InvalidArgumentException('Please enter a valid id document number.'); |
||
34 | } |
||
35 | |||
36 | if (is_null($id_type)) { |
||
37 | throw new \InvalidArgumentException('Please pass in a valid id type for the id document number you are testing.'); |
||
38 | } |
||
39 | |||
40 | if (!is_numeric($id_type)) { |
||
41 | throw new \InvalidArgumentException('Please pass in a numeric value for the id type wanting to be tested.'); |
||
42 | } |
||
43 | |||
44 | $id_type = (int)$id_type; |
||
45 | |||
46 | if ($id_type < 1 || $id_type > 3) { |
||
47 | throw new \InvalidArgumentException('Please enter a numeric value for the id type. 1 == ZA ID / 2 == Passport / 3 == ZA Asylum'); |
||
48 | } |
||
49 | |||
50 | if (1 == $id_type) { |
||
51 | if (!ctype_digit($id_document_number)) { |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | $idvalid = \PayBreak\Luhn\Luhn::validateNumber($id_document_number); |
||
56 | |||
57 | return ($idvalid); |
||
58 | } |
||
59 | |||
60 | return false; |
||
61 | } |
||
62 | } |
||
63 |