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