1 | <?php |
||
9 | class EcuadorValidations |
||
10 | { |
||
11 | /** |
||
12 | * Number of provinces of Ecuador |
||
13 | * |
||
14 | * @var \Illuminate\Config\Repository |
||
15 | */ |
||
16 | protected $provinces; |
||
17 | |||
18 | /** |
||
19 | * Length of the different types of identification |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $lenght; |
||
24 | |||
25 | /** |
||
26 | * Billing code for identification types |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $billingCode; |
||
31 | |||
32 | /** |
||
33 | * EcuadorValidations constructor. |
||
34 | */ |
||
35 | public function __construct() |
||
39 | |||
40 | /** |
||
41 | * Validate length identification, province code, third digit |
||
42 | * |
||
43 | * @param $number |
||
44 | * @param IdentificationContract $type |
||
45 | * @throws EcuadorIdentificationException |
||
46 | */ |
||
47 | protected function validateInitial($number, IdentificationContract $type) |
||
57 | |||
58 | /** |
||
59 | * Initial validation of the identification, not empty, only digits, not less than the given length. |
||
60 | * |
||
61 | * @param string $value CI or RUC |
||
62 | * @param int $len Number of characters required |
||
63 | * @return bool |
||
64 | * @throws EcuadorIdentificationException When the value is empty, when the value isn't digits and |
||
65 | * when the value doesn't have the required length |
||
66 | */ |
||
67 | private function validateLength($value, $len) |
||
83 | |||
84 | /** |
||
85 | * Validate the province code (first two numbers of CI/RUC) |
||
86 | * The first 2 positions correspond to the province where it was issued, |
||
87 | * so the first two numbers will not be greater than 24 or less than 1 |
||
88 | * |
||
89 | * @param string $value First two numbers of CI/RUC |
||
90 | * @return boolean |
||
91 | * @throws EcuadorIdentificationException When the province code is not between 1 and 24 |
||
92 | */ |
||
93 | private function validateProvinceCode($value) |
||
101 | |||
102 | /** |
||
103 | * Valid the third digit |
||
104 | * |
||
105 | * It allows the third digit of the document to be valid. |
||
106 | * Depending on the type field (type of identification) validations are performed. |
||
107 | * |
||
108 | * NATURAL_PERSON |
||
109 | * For Certificates and RUC of natural persons the third digit is less than 6 so |
||
110 | * it must be between 0 and 5 (0,1,2,3,4,5) |
||
111 | * |
||
112 | * PRIVATE_COMPANY |
||
113 | * For RUC of private companies the third digit must be equal to 9. |
||
114 | * |
||
115 | * PUBLIC_COMPANY |
||
116 | * For RUC of public companies the third digit must be equal to 6. |
||
117 | * |
||
118 | * @param string $value Third digit of CI/RUC |
||
119 | * @param IdentificationContract $type Type of identifier |
||
120 | * @return boolean |
||
121 | * @throws EcuadorIdentificationException When it does not comply with the validation according to the type of identifier |
||
122 | */ |
||
123 | private function validateThirdDigit($value, IdentificationContract $type) |
||
148 | |||
149 | /** |
||
150 | * Validation of the last digits |
||
151 | * |
||
152 | * Public Ruc => 0001 |
||
153 | * Other Ruc => 001 |
||
154 | * |
||
155 | * @param string $value The last digits |
||
156 | * @param IdentificationContract $type Type of identifier |
||
157 | * @return boolean |
||
158 | * @throws EcuadorIdentificationException When not equal to 001 |
||
159 | */ |
||
160 | protected function validateLastDigits($value, IdentificationContract $type) |
||
180 | |||
181 | /** |
||
182 | * Module 10 Algorithm to validate if Certificates and RUC of natural person are valid. |
||
183 | * |
||
184 | * Coefficients used to validate the tenth digit of the Certificates, |
||
185 | * are: 2, 1, 2, 1, 2, 1, 2, 1, 2 |
||
186 | * |
||
187 | * Step 1: Multiply each digit of the card by the coefficient, |
||
188 | * except for the verification digit (tenth digit), |
||
189 | * if it is greater than 10 sums between digits. Example: |
||
190 | * |
||
191 | * 2 1 2 1 2 1 2 1 2 (Coefficients) |
||
192 | * 1 7 1 0 0 3 4 0 6 (Certificate) |
||
193 | * 2 7 2 0 0 3 8 0 [12] => continue to step 2. |
||
194 | * |
||
195 | * Step 2: If any of the multiplication results is greater than 10, |
||
196 | * it is added between digits of the result. Example: [12] => 1 + 2 = Result (3) |
||
197 | * |
||
198 | * Step 3: The result of the multiplications is added. Example: |
||
199 | * 2 7 2 0 0 3 8 0 3 = Result (25) |
||
200 | * |
||
201 | * Step 4: The result of the sum is divided by 10 and the remainder of the division is obtained |
||
202 | * If the remainder is 0 the check digit is 0 |
||
203 | * Otherwise, the residue is subtracted from 10 |
||
204 | * |
||
205 | * If the result is equal to the verification digit, the value is correct. |
||
206 | * |
||
207 | * @param string $number Certificates or RUC of natural person |
||
208 | * @return boolean |
||
209 | * @throws EcuadorIdentificationException The verified digit does not match the verification digit. |
||
210 | */ |
||
211 | protected function moduleTen($number) |
||
242 | |||
243 | /** |
||
244 | * Module 11 Algorithm to validate if RUC of Public Companies and Private Companies are valid. |
||
245 | * |
||
246 | * For Public Companies (Third Digit => [6]): |
||
247 | * => The verifier digit is the ninth digit. |
||
248 | * => Coefficients used to validate the ninth digit of the Public Company RUC, (Third digit = [6]) |
||
249 | * are: 3, 2, 7, 6, 5, 4, 3, 2 |
||
250 | * |
||
251 | * |
||
252 | * For Private Companies (Third Digit => [9]): |
||
253 | * => The verifier digit is the tenth digit. |
||
254 | * => Coefficients used to validate the tenth digit of the Private Company RUC, (Third digit = [9]) |
||
255 | * are: 4, 3, 2, 7, 6, 5, 4, 3, 2 |
||
256 | * |
||
257 | * Step 1: Multiply each digit of the RUC with its respective coefficient, |
||
258 | * except the verification digit. Example: |
||
259 | * |
||
260 | * Public Companies |
||
261 | * 3 2 7 6 5 4 3 2 (Coefficients) |
||
262 | * 1 7 6 0 0 0 1 0 [4] 0 0 0 1 (Public RUC) [4] => Ninth Digit (Check Digit) |
||
263 | * 3 14 42 0 0 0 3 0 => Multiplication Result |
||
264 | * |
||
265 | * Private Companies |
||
266 | * 4 3 2 7 6 5 4 3 2 (Coefficients) |
||
267 | * 1 7 9 0 0 8 5 7 8 [3] 0 0 1 (Private RUC) [3] => Tenth Digit (Check Digit) |
||
268 | * 4 21 18 0 0 40 20 21 16 => Multiplication Result |
||
269 | * |
||
270 | * Step 2: The multiplication results are added |
||
271 | * |
||
272 | * Public Companies |
||
273 | * 3 14 42 0 0 0 3 0 = Result (62) |
||
274 | * |
||
275 | * * Private Companies |
||
276 | * 4 21 18 0 0 40 20 21 16 = Result (140) |
||
277 | * |
||
278 | * Step 3: The result of the sum is divided to 11 and the remainder of the division is obtained. |
||
279 | * If the remainder is 0 the check digit is 0 |
||
280 | * Otherwise, the residue is subtracted from 11 |
||
281 | * |
||
282 | * If the result is equal to the verification digit, the value is correct. |
||
283 | * |
||
284 | * @param string $number Private Company RUC or Public Compnay RUC |
||
285 | * @param IdentificationContract $type Type of identifier |
||
286 | * @return boolean |
||
287 | * @throws EcuadorIdentificationException The verified digit does not match the verification digit. |
||
288 | */ |
||
289 | protected function moduleEleven($number, IdentificationContract $type) |
||
322 | } |
||
323 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.