@@ -53,8 +53,9 @@ |
||
53 | 53 | */ |
54 | 54 | public static function getCiudad($comuna) |
55 | 55 | { |
56 | - if (!$comuna) |
|
57 | - return false; |
|
56 | + if (!$comuna) { |
|
57 | + return false; |
|
58 | + } |
|
58 | 59 | $comuna = mb_strtoupper($comuna, 'UTF-8'); |
59 | 60 | return isset(self::$ciudades[$comuna]) ? self::$ciudades[$comuna] : false; |
60 | 61 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public static function mergeRecursiveDistinct(array $array1, array $array2) |
43 | 43 | { |
44 | 44 | $merged = $array1; |
45 | - foreach ( $array2 as $key => &$value ) { |
|
45 | + foreach ($array2 as $key => &$value) { |
|
46 | 46 | if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { |
47 | 47 | $merged [$key] = self::mergeRecursiveDistinct( |
48 | 48 | $merged [$key], |
@@ -317,10 +317,10 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function verify($data, $signature, $pub_key = null, $signature_alg = OPENSSL_ALGO_SHA1) |
319 | 319 | { |
320 | - if ($pub_key === null) |
|
320 | + if ($pub_key===null) |
|
321 | 321 | $pub_key = $this->certs['cert']; |
322 | 322 | $pub_key = $this->normalizeCert($pub_key); |
323 | - return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg) == 1 ? true : false; |
|
323 | + return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg)==1 ? true : false; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | } else { |
452 | 452 | $digest_calculado = base64_encode(sha1($doc->C14N(), true)); |
453 | 453 | } |
454 | - return $digest_original == $digest_calculado; |
|
454 | + return $digest_original==$digest_calculado; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Método para generar un error usando una excepción de SowerPHP o terminar |
102 | 102 | * el script si no se está usando el framework |
103 | - * @param msg Mensaje del error |
|
103 | + * @param msg string del error |
|
104 | 104 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
105 | 105 | * @version 2017-08-04 |
106 | 106 | */ |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Método que entrega desde cuando es válida la firma |
191 | - * @return validFrom_time_t |
|
191 | + * @return string |
|
192 | 192 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
193 | 193 | * @version 2015-09-22 |
194 | 194 | */ |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Método que entrega hasta cuando es válida la firma |
202 | - * @return validTo_time_t |
|
202 | + * @return string |
|
203 | 203 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
204 | 204 | * @version 2015-09-22 |
205 | 205 | */ |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Método que obtiene el módulo de la clave privada |
235 | - * @return Módulo en base64 |
|
235 | + * @return string en base64 |
|
236 | 236 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
237 | 237 | * @version 2014-12-07 |
238 | 238 | */ |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Método que obtiene el exponente público de la clave privada |
247 | - * @return Exponente público en base64 |
|
247 | + * @return string público en base64 |
|
248 | 248 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
249 | 249 | * @version 2014-12-06 |
250 | 250 | */ |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Método para realizar la firma de datos |
297 | - * @param data Datos que se desean firmar |
|
297 | + * @param data string que se desean firmar |
|
298 | 298 | * @param signature_alg Algoritmo que se utilizará para firmar (por defect SHA1) |
299 | - * @return Firma digital de los datos en base64 o =false si no se pudo firmar |
|
299 | + * @return boolean|string digital de los datos en base64 o =false si no se pudo firmar |
|
300 | 300 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
301 | 301 | * @version 2014-12-08 |
302 | 302 | */ |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | /** |
313 | 313 | * Método que verifica la firma digital de datos |
314 | - * @param data Datos que se desean verificar |
|
314 | + * @param data string que se desean verificar |
|
315 | 315 | * @param signature Firma digital de los datos en base64 |
316 | 316 | * @param pub_key Certificado digital, clave pública, de la firma |
317 | 317 | * @param signature_alg Algoritmo que se usó para firmar (por defect SHA1) |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param xml Datos XML que se desean firmar |
336 | 336 | * @param reference Referencia a la que hace la firma |
337 | - * @return XML firmado o =false si no se pudo fimar |
|
337 | + * @return boolean|string firmado o =false si no se pudo fimar |
|
338 | 338 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
339 | 339 | * @version 2017-10-22 |
340 | 340 | */ |
@@ -168,8 +168,9 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function getName() |
170 | 170 | { |
171 | - if (isset($this->data['subject']['CN'])) |
|
172 | - return $this->data['subject']['CN']; |
|
171 | + if (isset($this->data['subject']['CN'])) { |
|
172 | + return $this->data['subject']['CN']; |
|
173 | + } |
|
173 | 174 | return $this->error('No fue posible obtener el Name (subject.CN) de la firma'); |
174 | 175 | } |
175 | 176 | |
@@ -353,8 +354,9 @@ discard block |
||
353 | 354 | */ |
354 | 355 | public function verify($data, $signature, $pub_key = null, $signature_alg = OPENSSL_ALGO_SHA1) |
355 | 356 | { |
356 | - if ($pub_key === null) |
|
357 | - $pub_key = $this->certs['cert']; |
|
357 | + if ($pub_key === null) { |
|
358 | + $pub_key = $this->certs['cert']; |
|
359 | + } |
|
358 | 360 | $pub_key = $this->normalizeCert($pub_key); |
359 | 361 | return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg) == 1 ? true : false; |
360 | 362 | } |
@@ -453,8 +455,9 @@ discard block |
||
453 | 455 | // calcular SignatureValue |
454 | 456 | $SignedInfo = $doc->saveHTML($Signature->getElementsByTagName('SignedInfo')->item(0)); |
455 | 457 | $firma = $this->sign($SignedInfo); |
456 | - if (!$firma) |
|
457 | - return false; |
|
458 | + if (!$firma) { |
|
459 | + return false; |
|
460 | + } |
|
458 | 461 | $signature = wordwrap($firma, $this->config['wordwrap'], "\n", true); |
459 | 462 | // reemplazar valores en la firma de |
460 | 463 | $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue = $signature; |
@@ -486,8 +489,9 @@ discard block |
||
486 | 489 | $signature = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
487 | 490 | $pub_key = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
488 | 491 | // verificar firma |
489 | - if (!$this->verify($signed_info, $signature, $pub_key)) |
|
490 | - return false; |
|
492 | + if (!$this->verify($signed_info, $signature, $pub_key)) { |
|
493 | + return false; |
|
494 | + } |
|
491 | 495 | // verificar digest |
492 | 496 | $digest_original = $Signature->getElementsByTagName('DigestValue')->item(0)->nodeValue; |
493 | 497 | if ($tag) { |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public static function read($archivo, $separador = ';', $delimitadortexto = '"') |
48 | 48 | { |
49 | - if (($handle = fopen($archivo, 'r')) !== FALSE) { |
|
49 | + if (($handle = fopen($archivo, 'r'))!==FALSE) { |
|
50 | 50 | $data = array(); |
51 | 51 | $i = 0; |
52 | - while (($row = fgetcsv($handle, 0, $separador, $delimitadortexto)) !== FALSE) { |
|
52 | + while (($row = fgetcsv($handle, 0, $separador, $delimitadortexto))!==FALSE) { |
|
53 | 53 | $j = 0; |
54 | 54 | foreach ($row as &$col) { |
55 | 55 | $data[$i][$j++] = $col; |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | header('Content-Disposition: attachment; filename='.$archivo.'.csv'); |
78 | 78 | header('Pragma: no-cache'); |
79 | 79 | header('Expires: 0'); |
80 | - foreach($data as &$row) { |
|
81 | - foreach($row as &$col) { |
|
80 | + foreach ($data as &$row) { |
|
81 | + foreach ($row as &$col) { |
|
82 | 82 | $col = $delimitadortexto.rtrim(str_replace('<br />', ', ', strip_tags($col, '<br>')), " \t\n\r\0\x0B,").$delimitadortexto; |
83 | 83 | } |
84 | - echo implode($separador, $row),"\r\n"; |
|
84 | + echo implode($separador, $row), "\r\n"; |
|
85 | 85 | unset($row); |
86 | 86 | } |
87 | 87 | unset($data); |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | public static function save(array $data, $archivo, $separador = ';', $delimitadortexto = '"') |
101 | 101 | { |
102 | 102 | $fd = fopen($archivo, 'w'); |
103 | - foreach($data as &$row) { |
|
104 | - foreach($row as &$col) { |
|
103 | + foreach ($data as &$row) { |
|
104 | + foreach ($row as &$col) { |
|
105 | 105 | $col = $delimitadortexto.rtrim(str_replace('<br />', ', ', strip_tags($col, '<br>')), " \t\n\r\0\x0B,").$delimitadortexto; |
106 | 106 | } |
107 | 107 | fwrite($fd, implode($separador, $row)."\r\n"); |
@@ -174,12 +174,14 @@ |
||
174 | 174 | public static function get($codigo, $args = null) |
175 | 175 | { |
176 | 176 | // si no hay glosa asociada al código se entrega el mismo código |
177 | - if (!isset(self::$glosas[(int)$codigo])) |
|
178 | - return (int)$codigo; |
|
177 | + if (!isset(self::$glosas[(int)$codigo])) { |
|
178 | + return (int)$codigo; |
|
179 | + } |
|
179 | 180 | // si los argumentos no son un arreglo se obtiene arreglo a partir |
180 | 181 | // de los argumentos pasados a la función |
181 | - if (!is_array($args)) |
|
182 | - $args = array_slice(func_get_args(), 1); |
|
182 | + if (!is_array($args)) { |
|
183 | + $args = array_slice(func_get_args(), 1); |
|
184 | + } |
|
183 | 185 | // entregar glosa |
184 | 186 | return vsprintf(I18n::translate(self::$glosas[(int)$codigo], 'estados'), $args); |
185 | 187 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Método que realiza la firma del DTE cedido |
71 | - * @param Firma objeto que representa la Firma Electrónca |
|
71 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
72 | 72 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
73 | 73 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
74 | 74 | * @version 2016-12-10 |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | private $dtes = []; ///< Objetos con los DTE que se enviarán |
35 | - private $config = [ // 0: DTE, 1: boleta |
|
35 | + private $config = [// 0: DTE, 1: boleta |
|
36 | 36 | 'SubTotDTE_max' => [20, 2], ///< máxima cantidad de tipos de documentos en el envío |
37 | 37 | 'DTE_max' => [2000, 1000], ///< máxima cantidad de DTE en un envío |
38 | 38 | 'tipos' => ['EnvioDTE', 'EnvioBOLETA'], ///< Tag para el envío, según si son Boletas o no |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | public function agregar(Dte $DTE) |
51 | 51 | { |
52 | 52 | // determinar el tipo del envío (DTE o boleta) |
53 | - if ($this->tipo === null) { |
|
53 | + if ($this->tipo===null) { |
|
54 | 54 | $this->tipo = (int)$DTE->esBoleta(); |
55 | 55 | } |
56 | 56 | // validar que el tipo de documento sea del tipo que se espera |
57 | - else if ((int)$DTE->esBoleta() != $this->tipo) { |
|
57 | + else if ((int)$DTE->esBoleta()!=$this->tipo) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | // |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | 'RutEnvia' => $Dte->getEmisor(), |
222 | 222 | 'RutReceptor' => $Dte->getReceptor(), |
223 | 223 | 'FchResol' => date('Y-m-d'), |
224 | - 'NroResol' => ($Dte->getCertificacion()?'0':'').'9999', |
|
224 | + 'NroResol' => ($Dte->getCertificacion() ? '0' : '').'9999', |
|
225 | 225 | ]); |
226 | 226 | if (!parent::loadXML($this->generar())) { |
227 | 227 | return false; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | { |
302 | 302 | $fecha = '9999-12-31'; |
303 | 303 | foreach ($this->getDocumentos() as $Dte) { |
304 | - if ($Dte->getFechaEmision() < $fecha) |
|
304 | + if ($Dte->getFechaEmision()<$fecha) |
|
305 | 305 | $fecha = $Dte->getFechaEmision(); |
306 | 306 | } |
307 | 307 | return $fecha; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | { |
317 | 317 | $fecha = '0000-01-01'; |
318 | 318 | foreach ($this->getDocumentos() as $Dte) { |
319 | - if ($Dte->getFechaEmision() > $fecha) |
|
319 | + if ($Dte->getFechaEmision()>$fecha) |
|
320 | 320 | $fecha = $Dte->getFechaEmision(); |
321 | 321 | } |
322 | 322 | return $fecha; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $e = substr($e, 0, -2); |
376 | 376 | $d = (int)$nodo_dte->getElementsByTagName('TipoDTE')->item(0)->nodeValue; |
377 | 377 | $f = (int)$nodo_dte->getElementsByTagName('Folio')->item(0)->nodeValue; |
378 | - if ($folio == $f and $dte == $d and $emisor == $e) { |
|
378 | + if ($folio==$f and $dte==$d and $emisor==$e) { |
|
379 | 379 | return new Dte($nodo_dte->C14N(), false); // cargar DTE sin normalizar |
380 | 380 | } |
381 | 381 | } |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | if ($X509Certificate[1]==' ' or $X509Certificate[1]=="\t") { |
433 | 433 | $lineas = explode("\n", $X509Certificate); |
434 | 434 | $X509Certificate = ''; |
435 | - foreach($lineas as $l) { |
|
435 | + foreach ($lineas as $l) { |
|
436 | 436 | $X509Certificate .= trim($l); |
437 | 437 | } |
438 | 438 | } |
439 | 439 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE-----'; |
440 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
440 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
441 | 441 | return $valid and $DigestValue===base64_encode(sha1($SetDTE, true)); |
442 | 442 | } |
443 | 443 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Método que agrega un DTE al listado que se enviará |
45 | - * @param DTE Objeto del DTE |
|
45 | + * @param DTE Dte del DTE |
|
46 | 46 | * @return =true si se pudo agregar el DTE o =false si no se agregó por exceder el límite de un envío |
47 | 47 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
48 | 48 | * @version 2015-12-11 |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | /** |
396 | 396 | * Método que determina el estado de validación sobre el envío |
397 | 397 | * @param datos Arreglo con datos para hacer las validaciones |
398 | - * @return Código del estado de la validación |
|
398 | + * @return integer del estado de la validación |
|
399 | 399 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
400 | 400 | * @version 2019-07-03 |
401 | 401 | */ |
@@ -135,8 +135,9 @@ discard block |
||
135 | 135 | public function generar() |
136 | 136 | { |
137 | 137 | // si ya se había generado se entrega directamente |
138 | - if ($this->xml_data) |
|
139 | - return $this->xml_data; |
|
138 | + if ($this->xml_data) { |
|
139 | + return $this->xml_data; |
|
140 | + } |
|
140 | 141 | // si no hay DTEs para generar entregar falso |
141 | 142 | if (!isset($this->dtes[0])) { |
142 | 143 | \sasco\LibreDTE\Log::write( |
@@ -185,8 +186,9 @@ discard block |
||
185 | 186 | $SubTotDTE = []; |
186 | 187 | $subtotales = []; |
187 | 188 | foreach ($this->dtes as &$DTE) { |
188 | - if (!isset($subtotales[$DTE->getTipo()])) |
|
189 | - $subtotales[$DTE->getTipo()] = 0; |
|
189 | + if (!isset($subtotales[$DTE->getTipo()])) { |
|
190 | + $subtotales[$DTE->getTipo()] = 0; |
|
191 | + } |
|
190 | 192 | $subtotales[$DTE->getTipo()]++; |
191 | 193 | } |
192 | 194 | foreach ($subtotales as $tipo => $subtotal) { |
@@ -301,8 +303,9 @@ discard block |
||
301 | 303 | { |
302 | 304 | $fecha = '9999-12-31'; |
303 | 305 | foreach ($this->getDocumentos() as $Dte) { |
304 | - if ($Dte->getFechaEmision() < $fecha) |
|
305 | - $fecha = $Dte->getFechaEmision(); |
|
306 | + if ($Dte->getFechaEmision() < $fecha) { |
|
307 | + $fecha = $Dte->getFechaEmision(); |
|
308 | + } |
|
306 | 309 | } |
307 | 310 | return $fecha; |
308 | 311 | } |
@@ -316,8 +319,9 @@ discard block |
||
316 | 319 | { |
317 | 320 | $fecha = '0000-01-01'; |
318 | 321 | foreach ($this->getDocumentos() as $Dte) { |
319 | - if ($Dte->getFechaEmision() > $fecha) |
|
320 | - $fecha = $Dte->getFechaEmision(); |
|
322 | + if ($Dte->getFechaEmision() > $fecha) { |
|
323 | + $fecha = $Dte->getFechaEmision(); |
|
324 | + } |
|
321 | 325 | } |
322 | 326 | return $fecha; |
323 | 327 | } |
@@ -371,8 +375,9 @@ discard block |
||
371 | 375 | $DTEs = $this->xml->getElementsByTagName('DTE'); |
372 | 376 | foreach ($DTEs as $nodo_dte) { |
373 | 377 | $e = $nodo_dte->getElementsByTagName('RUTEmisor')->item(0)->nodeValue; |
374 | - if (is_numeric($emisor)) |
|
375 | - $e = substr($e, 0, -2); |
|
378 | + if (is_numeric($emisor)) { |
|
379 | + $e = substr($e, 0, -2); |
|
380 | + } |
|
376 | 381 | $d = (int)$nodo_dte->getElementsByTagName('TipoDTE')->item(0)->nodeValue; |
377 | 382 | $f = (int)$nodo_dte->getElementsByTagName('Folio')->item(0)->nodeValue; |
378 | 383 | if ($folio == $f and $dte == $d and $emisor == $e) { |
@@ -66,4 +66,4 @@ |
||
66 | 66 | |
67 | 67 | // si hubo errores mostrar |
68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
69 | - echo $error,"\n"; |
|
69 | + echo $error, "\n"; |
@@ -98,5 +98,6 @@ |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | // si hubo errores mostrar |
101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
102 | 102 | echo $error,"\n"; |
103 | +} |
@@ -66,4 +66,4 @@ |
||
66 | 66 | |
67 | 67 | // si hubo errores mostrar |
68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
69 | - echo $error,"\n"; |
|
69 | + echo $error, "\n"; |
@@ -65,5 +65,6 @@ |
||
65 | 65 | var_dump($track_id); |
66 | 66 | |
67 | 67 | // si hubo errores mostrar |
68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
69 | 69 | echo $error,"\n"; |
70 | +} |