1 | <?php |
||
7 | final class Cnh implements DocumentInterface |
||
8 | { |
||
9 | const LENGTH = 11; |
||
10 | |||
11 | const LABEL = 'CNH'; |
||
12 | |||
13 | const REGEX = '/^([\d]{3})([\d]{3})([\d]{4})([\d]{1})$/'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $cnh; |
||
19 | |||
20 | /** |
||
21 | * Cnh constructor. |
||
22 | * |
||
23 | * @param string $cnh Only accept numbers |
||
24 | */ |
||
25 | 9 | public function __construct($cnh) |
|
31 | |||
32 | /** |
||
33 | * Check if CNH is not empty and is a valid number. |
||
34 | * |
||
35 | * @param string $number |
||
36 | * |
||
37 | * @throws InvalidArgumentException when CNH is empty |
||
38 | * @throws InvalidArgumentException when CNH is not valid number |
||
39 | */ |
||
40 | 9 | private function validate($number) |
|
49 | |||
50 | /** |
||
51 | * Validates CNH is a valid number. |
||
52 | * |
||
53 | * @param string $number A number to be validate. |
||
54 | * |
||
55 | * @return bool Returns true if it is a valid number, otherwise false. |
||
56 | */ |
||
57 | 6 | private function isValidCV($number) |
|
71 | |||
72 | /** |
||
73 | * Formats CNH number |
||
74 | * |
||
75 | * @return string Returns formatted number. |
||
76 | */ |
||
77 | 1 | public function format() |
|
81 | |||
82 | /** |
||
83 | * Returns the CNH number |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 2 | public function __toString() |
|
91 | |||
92 | 4 | private function calculateFirstDigit($number) |
|
102 | |||
103 | 4 | private function calculateSecondDigit($number) |
|
113 | } |
||
114 |