1 | <?php |
||
10 | class BaseIdentification implements IdentificationContract |
||
11 | { |
||
12 | /** |
||
13 | * Number of provinces of Ecuador |
||
14 | * @var int |
||
15 | */ |
||
16 | protected $provinces = 24; |
||
17 | |||
18 | /** |
||
19 | * Length of the different types of identification |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $lenght = 0; |
||
23 | |||
24 | /** |
||
25 | * Billing code for identification types |
||
26 | * @var string|null |
||
27 | */ |
||
28 | protected $billingCode = null; |
||
29 | |||
30 | /** |
||
31 | * Third digit of the identification number |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $thirdDigit; |
||
35 | |||
36 | /** |
||
37 | * Lasts digits of the identification number |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $lastDigits = ''; |
||
41 | |||
42 | /** |
||
43 | * Represents the position of the verifying digit in the identification number |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $checkDigitPosition; |
||
47 | |||
48 | /** |
||
49 | * Represents the check coefficients for the identification number |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $coefficients; |
||
53 | |||
54 | /** |
||
55 | * Validate length identification, province code, third digit, lasts digits and module validations |
||
56 | * |
||
57 | * @param string $identification_number Identification document |
||
58 | * @return string|null Billing code or null |
||
59 | * @throws IdentificationException |
||
60 | */ |
||
61 | public function validate(string $identification_number) |
||
76 | |||
77 | /** |
||
78 | * Initial validation of the identification, not empty, only digits, not less than the given length. |
||
79 | * |
||
80 | * @param string $identification_number Identification document |
||
81 | * @throws IdentificationException |
||
82 | */ |
||
83 | protected function lenghtValidation(string $identification_number): void |
||
97 | |||
98 | /** |
||
99 | * Validate the province code (first two numbers of CI/RUC) |
||
100 | * The first 2 positions correspond to the province where it was issued, |
||
101 | * so the first two numbers will not be greater than 24 or less than 1 |
||
102 | * |
||
103 | * @param string $identification_number Identification document |
||
104 | * @throws IdentificationException |
||
105 | */ |
||
106 | protected function provinceCodeValidation(string $identification_number): void |
||
114 | |||
115 | /** |
||
116 | * Valid the third digit |
||
117 | * |
||
118 | * @param string $identification_number Identification document |
||
119 | * @throws IdentificationException |
||
120 | */ |
||
121 | protected function thirdDigitValidation(string $identification_number): void |
||
129 | |||
130 | /** |
||
131 | * Valid the lasts digits |
||
132 | * |
||
133 | * @param string $identification_number Identification document |
||
134 | * @throws IdentificationException |
||
135 | */ |
||
136 | protected function lastsDigitsValidation(string $identification_number): void |
||
144 | |||
145 | /** |
||
146 | * Module 10 Algorithm to validate if Certificates and RUC of natural person are valid. |
||
147 | * |
||
148 | * @param string $identification_number Identification document |
||
149 | * @throws IdentificationException The verified digit does not match the verification digit. |
||
150 | */ |
||
151 | protected function moduleTenValidation(string $identification_number): void |
||
177 | |||
178 | /** |
||
179 | * Module 11 Algorithm to validate if RUC of Public Companies and Private Companies are valid. |
||
180 | * |
||
181 | * @param string $identification_number Identification document |
||
182 | * @throws IdentificationException The verified digit does not match the verification digit. |
||
183 | */ |
||
184 | protected function moduleElevenValidation(string $identification_number): void |
||
204 | |||
205 | /** |
||
206 | * Gets the province code value |
||
207 | * |
||
208 | * @param string $identification_number Identification document |
||
209 | * @return false|string Value of the province code number |
||
210 | */ |
||
211 | protected function getProvinceCodeValue(string $identification_number) |
||
215 | |||
216 | /** |
||
217 | * Gets the third digit number |
||
218 | * |
||
219 | * @param string $identification_number Identification document |
||
220 | * @return false|string Value of the third digit number |
||
221 | */ |
||
222 | protected function getThirdDigitValue(string $identification_number) |
||
226 | |||
227 | /** |
||
228 | * Gets the lasts digits value |
||
229 | * |
||
230 | * @param string $identification_number Identification document |
||
231 | * @return false|string Value of the lasts digits |
||
232 | */ |
||
233 | protected function getLastsDigitsValue(string $identification_number) |
||
237 | |||
238 | /** |
||
239 | * Gets the value of the verification number |
||
240 | * |
||
241 | * @param string $identification_number Identification document |
||
242 | * @return false|string Value of the verification number |
||
243 | */ |
||
244 | protected function getCheckDigitValue(string $identification_number) |
||
248 | |||
249 | /** |
||
250 | * Get identification numbers for verification as Array |
||
251 | * |
||
252 | * @param string $identification_number Identification document |
||
253 | * @return array Identification numbers for verification |
||
254 | */ |
||
255 | protected function getNumbersAsArray(string $identification_number): array |
||
259 | } |
||
260 |