1 | <?php |
||
18 | abstract class AbstractDocument implements DigitCalculable, Formattable |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $number; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $digit; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $length; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $numberOfDigits; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $type; |
||
44 | |||
45 | /** |
||
46 | * AbstractDocument constructor. |
||
47 | * |
||
48 | * @param string $number Numeric section with checker digit. |
||
49 | * @param int $length Max length of document. |
||
50 | * @param int $numberOfDigits Max length of checker digits. |
||
51 | * @param string $type Document name/type. |
||
52 | */ |
||
53 | 627 | public function __construct($number, $length, $numberOfDigits, $type) |
|
62 | |||
63 | 5 | public function __get($name) |
|
67 | |||
68 | public function __set($name, $value) |
||
72 | |||
73 | /** |
||
74 | * Check if document number is valid. |
||
75 | * |
||
76 | * @param string $number Numeric section with checker digit. |
||
77 | * |
||
78 | * @throws InvalidDocumentException when number is empty |
||
79 | * @throws InvalidDocumentException when number is not valid |
||
80 | */ |
||
81 | 627 | protected function validate($number) |
|
90 | |||
91 | /** |
||
92 | * Validates number is a valid. |
||
93 | * |
||
94 | * @param string $number Numeric section with checker digit. |
||
95 | * |
||
96 | * @return bool Returns true if it is a valid number, otherwise false. |
||
97 | */ |
||
98 | 555 | protected function isValid($number) |
|
116 | |||
117 | /** |
||
118 | * Handle number to string. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 430 | public function __toString() |
|
126 | |||
127 | /** |
||
128 | * Extracts the base number document. |
||
129 | * |
||
130 | * @param string $number Number of document. |
||
131 | * |
||
132 | * @return string Returns only base number without checker digit. |
||
133 | */ |
||
134 | 118 | protected function extractBaseNumber($number) |
|
138 | |||
139 | /** |
||
140 | * Extracts the checker digit from document number. |
||
141 | * |
||
142 | * @param string $number Number of document. |
||
143 | * |
||
144 | * @return string Returns only checker digit. |
||
145 | */ |
||
146 | 151 | protected function extractCheckerDigit($number) |
|
150 | } |
||
151 |