Completed
Push — master ( ff361f...76e49f )
by Esteban De La Fuente
01:50
created
examples/011-set_pruebas_factura_exenta.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +10 added lines, -6 removed lines patch added patch discarded remove patch
@@ -411,17 +411,20 @@  discard block
 block discarded – undo
411 411
 // Objetos de Firma, Folios y EnvioDTE
412 412
 $Firma = new \sasco\LibreDTE\FirmaElectronica($config['firma']);
413 413
 $Folios = [];
414
-foreach ($folios as $tipo => $cantidad)
414
+foreach ($folios as $tipo => $cantidad) {
415 415
     $Folios[$tipo] = new \sasco\LibreDTE\Sii\Folios(file_get_contents('xml/folios/'.$tipo.'.xml'));
416
+}
416 417
 $EnvioDTE = new \sasco\LibreDTE\Sii\EnvioDte();
417 418
 
418 419
 // generar cada DTE, timbrar, firmar y agregar al sobre de EnvioDTE
419 420
 foreach ($set_pruebas as $documento) {
420 421
     $DTE = new \sasco\LibreDTE\Sii\Dte($documento);
421
-    if (!$DTE->timbrar($Folios[$DTE->getTipo()]))
422
-        break;
423
-    if (!$DTE->firmar($Firma))
424
-        break;
422
+    if (!$DTE->timbrar($Folios[$DTE->getTipo()])) {
423
+            break;
424
+    }
425
+    if (!$DTE->firmar($Firma)) {
426
+            break;
427
+    }
425 428
     $EnvioDTE->agregar($DTE);
426 429
 }
427 430
 
@@ -433,5 +436,6 @@  discard block
 block discarded – undo
433 436
 var_dump($track_id);
434 437
 
435 438
 // si hubo errores mostrar
436
-foreach (\sasco\LibreDTE\Log::readAll() as $error)
439
+foreach (\sasco\LibreDTE\Log::readAll() as $error) {
437 440
     echo $error,"\n";
441
+}
Please login to merge, or discard this patch.
examples/015-etapa_intercambio_RecepcionDTE.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,5 +98,6 @@
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
examples/017-etapa_intercambio_ResultadoDTE.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,5 +98,6 @@
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
examples/012-set_pruebas_ventas.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,5 +65,6 @@
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
examples/031-libro_boleta.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,5 +98,6 @@
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
examples/022-libro_ventas_csv.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,4 +66,4 @@
 block discarded – undo
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";
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,5 +65,6 @@
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
lib/Sii/RegistroCompraVenta.php 2 patches
Doc Comments   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
     /**
57 57
      * Constructor, obtiene el token de la sesión y lo guarda
58
-     * @param Firma Objeto con la firma electrónica
58
+     * @param Firma \sasco\LibreDTE\FirmaElectronica con la firma electrónica
59 59
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
60 60
      * @version 2017-08-28
61 61
      */
@@ -97,6 +97,8 @@  discard block
 block discarded – undo
97 97
      * Método que entrega los eventos asociados a un DTE
98 98
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
99 99
      * @version 2017-08-28
100
+     * @param string $dte
101
+     * @param string $folio
100 102
      */
101 103
     public function listarEventosHistDoc($rut, $dv, $dte, $folio)
102 104
     {
@@ -184,10 +186,10 @@  discard block
 block discarded – undo
184 186
 
185 187
     /**
186 188
      * Método para realizar una solicitud al servicio web del SII
187
-     * @param request Nombre de la función que se ejecutará en el servicio web
189
+     * @param request string de la función que se ejecutará en el servicio web
188 190
      * @param args Argumentos que se pasarán al servicio web
189
-     * @param retry Intentos que se realizarán como máximo para obtener respuesta
190
-     * @return Objeto o String con la respuesta (depende servicio web)
191
+     * @param retry integer que se realizarán como máximo para obtener respuesta
192
+     * @return string o String con la respuesta (depende servicio web)
191 193
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
192 194
      * @version 2017-08-28
193 195
      */
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -220,7 +220,7 @@
 block discarded – undo
220 220
             \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, $msg));
221 221
             return false;
222 222
         }
223
-        for ($i=0; $i<$retry; $i++) {
223
+        for ($i = 0; $i<$retry; $i++) {
224 224
             try {
225 225
                 $body = call_user_func_array([$soap, $request], $args);
226 226
                 break;
Please login to merge, or discard this patch.
lib/XML.php 3 patches
Doc Comments   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
      * Método que genera nodos XML a partir de un arreglo
53 53
      * @param data Arreglo con los datos que se usarán para generar XML
54 54
      * @param namespace Arreglo con el espacio de nombres para el XML que se generará (URI y prefijo)
55
-     * @param parent DOMElement padre para los elementos, o =null para que sea la raíz
56
-     * @return Objeto \sasco\LibreDTE\XML
55
+     * @param parent \DOMElement padre para los elementos, o =null para que sea la raíz
56
+     * @return XML \sasco\LibreDTE\XML
57 57
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
58 58
      * @version 2017-10-22
59 59
      */
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
     /**
154 154
      * Método para realizar consultas XPATH al documento XML
155 155
      * @param expression Expresión XPath a ejecutar
156
-     * @return DOMNodeList
156
+     * @return \DOMNodeList
157 157
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
158 158
      * @version 2015-08-05
159 159
      */
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * Método que cuenta los nodos con el mismo nombre hijos deun DOMElement
275 275
      * No sirve usar: $dom->getElementsByTagName($tagName)->length ya que esto
276 276
      * entrega todos los nodos con el nombre, sean hijos, nietos, etc.
277
-     * @return Cantidad de nodos hijos con el mismo nombre en el DOMElement
277
+     * @return integer de nodos hijos con el mismo nombre en el DOMElement
278 278
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
279 279
      * @version 2015-09-07
280 280
      */
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
     /**
316 316
      * Método que entrega el nombre del archivo del schema del XML
317
-     * @return Nombre del schema o bien =false si no se encontró
317
+     * @return string del schema o bien =false si no se encontró
318 318
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
319 319
      * @version 2015-12-14
320 320
      */
@@ -356,6 +356,7 @@  discard block
 block discarded – undo
356 356
      * respeta el estándar y las requiere convertidas
357 357
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
358 358
      * @version 2017-01-20
359
+     * @param string $xml
359 360
      */
360 361
     private function fixEntities($xml)
361 362
     {
Please login to merge, or discard this patch.
Braces   +42 added lines, -30 removed lines patch added patch discarded remove patch
@@ -120,8 +120,9 @@  discard block
 block discarded – undo
120 120
     private function sanitize($txt)
121 121
     {
122 122
         // si no se paso un texto o bien es un número no se hace nada
123
-        if (!$txt or is_numeric($txt))
124
-            return $txt;
123
+        if (!$txt or is_numeric($txt)) {
124
+                    return $txt;
125
+        }
125 126
         // convertir "predefined entities" de XML
126 127
         $txt = str_replace(
127 128
             ['&amp;', '&#38;', '&lt;', '&#60;', '&gt;', '&#62', '&quot;', '&#34;', '&apos;', '&#39;'],
@@ -174,8 +175,9 @@  discard block
 block discarded – undo
174 175
     {
175 176
         if ($xpath) {
176 177
             $node = $this->xpath($xpath)->item(0);
177
-            if (!$node)
178
-                return false;
178
+            if (!$node) {
179
+                            return false;
180
+            }
179 181
             $xml = $this->utf2iso($node->C14N());
180 182
             $xml = $this->fixEntities($xml);
181 183
         } else {
@@ -222,12 +224,15 @@  discard block
 block discarded – undo
222 224
     public function toArray(\DOMElement $dom = null, array &$array = null, $arregloNodos = false)
223 225
     {
224 226
         // determinar valores de parámetros
225
-        if (!$dom)
226
-            $dom = $this->documentElement;
227
-        if (!$dom)
228
-            return false;
229
-        if ($array===null)
230
-            $array = [$dom->tagName => null];
227
+        if (!$dom) {
228
+                    $dom = $this->documentElement;
229
+        }
230
+        if (!$dom) {
231
+                    return false;
232
+        }
233
+        if ($array===null) {
234
+                    $array = [$dom->tagName => null];
235
+        }
231 236
         // agregar atributos del nodo
232 237
         if ($dom->hasAttributes()) {
233 238
             $array[$dom->tagName]['@attributes'] = [];
@@ -243,22 +248,24 @@  discard block
 block discarded – undo
243 248
                     if ($textContent!="") {
244 249
                         if ($dom->childNodes->length==1 and empty($array[$dom->tagName])) {
245 250
                             $array[$dom->tagName] = $textContent;
246
-                        } else
247
-                            $array[$dom->tagName]['@value'] = $textContent;
251
+                        } else {
252
+                                                    $array[$dom->tagName]['@value'] = $textContent;
253
+                        }
248 254
                     }
249
-                }
250
-                else if ($child instanceof \DOMElement) {
255
+                } else if ($child instanceof \DOMElement) {
251 256
                     $nodos_gemelos = $this->countTwins($dom, $child->tagName);
252 257
                     if ($nodos_gemelos==1) {
253
-                        if ($arregloNodos)
254
-                            $this->toArray($child, $array);
255
-                        else
256
-                            $this->toArray($child, $array[$dom->tagName]);
258
+                        if ($arregloNodos) {
259
+                                                    $this->toArray($child, $array);
260
+                        } else {
261
+                                                    $this->toArray($child, $array[$dom->tagName]);
262
+                        }
257 263
                     }
258 264
                     // crear arreglo con nodos hijos que tienen el mismo nombre de tag
259 265
                     else {
260
-                        if (!isset($array[$dom->tagName][$child->tagName]))
261
-                            $array[$dom->tagName][$child->tagName] = [];
266
+                        if (!isset($array[$dom->tagName][$child->tagName])) {
267
+                                                    $array[$dom->tagName][$child->tagName] = [];
268
+                        }
262 269
                         $siguiente = count($array[$dom->tagName][$child->tagName]);
263 270
                         $array[$dom->tagName][$child->tagName][$siguiente] = [];
264 271
                         $this->toArray($child, $array[$dom->tagName][$child->tagName][$siguiente], true);
@@ -282,8 +289,9 @@  discard block
 block discarded – undo
282 289
     {
283 290
         $twins = 0;
284 291
         foreach ($dom->childNodes as $child) {
285
-            if ($child instanceof \DOMElement and $child->tagName==$tagName)
286
-                $twins++;
292
+            if ($child instanceof \DOMElement and $child->tagName==$tagName) {
293
+                            $twins++;
294
+            }
287 295
         }
288 296
         return $twins;
289 297
     }
@@ -297,8 +305,9 @@  discard block
 block discarded – undo
297 305
     public function getErrors()
298 306
     {
299 307
         $errors = [];
300
-        foreach (libxml_get_errors() as $e)
301
-            $errors[] = $e->message;
308
+        foreach (libxml_get_errors() as $e) {
309
+                    $errors[] = $e->message;
310
+        }
302 311
         return $errors;
303 312
     }
304 313
 
@@ -321,8 +330,9 @@  discard block
 block discarded – undo
321 330
     public function getSchema()
322 331
     {
323 332
         $schemaLocation = $this->documentElement->getAttribute('xsi:schemaLocation');
324
-        if (!$schemaLocation or strpos($schemaLocation, ' ')===false)
325
-            return false;
333
+        if (!$schemaLocation or strpos($schemaLocation, ' ')===false) {
334
+                    return false;
335
+        }
326 336
         list($uri, $xsd) = explode(' ', $schemaLocation);
327 337
         return $xsd;
328 338
     }
@@ -363,10 +373,12 @@  discard block
 block discarded – undo
363 373
         $n_letras = strlen($xml);
364 374
         $convertir = false;
365 375
         for ($i=0; $i<$n_letras; ++$i) {
366
-            if ($xml[$i]=='>')
367
-                $convertir = true;
368
-            if ($xml[$i]=='<')
369
-                $convertir = false;
376
+            if ($xml[$i]=='>') {
377
+                            $convertir = true;
378
+            }
379
+            if ($xml[$i]=='<') {
380
+                            $convertir = false;
381
+            }
370 382
             if ($convertir) {
371 383
                 $l = $xml[$i]=='\'' ? '&apos;' : ($xml[$i]=='"' ? '&quot;' : $xml[$i]);
372 384
             } else {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      */
198 198
     private function utf2iso($string)
199 199
     {
200
-        return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($string) : $string;
200
+        return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($string) : $string;
201 201
     }
202 202
 
203 203
     /**
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         }
238 238
         // agregar nodos hijos
239 239
         if ($dom->hasChildNodes()) {
240
-            foreach($dom->childNodes as $child) {
240
+            foreach ($dom->childNodes as $child) {
241 241
                 if ($child instanceof \DOMText) {
242 242
                     $textContent = trim($child->textContent);
243 243
                     if ($textContent!="") {
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
         $newXML = '';
363 363
         $n_letras = strlen($xml);
364 364
         $convertir = false;
365
-        for ($i=0; $i<$n_letras; ++$i) {
365
+        for ($i = 0; $i<$n_letras; ++$i) {
366 366
             if ($xml[$i]=='>')
367 367
                 $convertir = true;
368 368
             if ($xml[$i]=='<')
Please login to merge, or discard this patch.
lib/Sii/Folios.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -254,7 +254,7 @@
 block discarded – undo
254 254
 
255 255
     /**
256 256
      * Método que indica si el CAF es de certificación o no
257
-     * @return bool =true si los folios son del ambiente de certificación, =null si no se pudo determinar
257
+     * @return boolean|null =true si los folios son del ambiente de certificación, =null si no se pudo determinar
258 258
      * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
259 259
      * @version 2015-10-30
260 260
      */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
         // validar firma del SII sobre los folios
64 64
         $firma = $this->getFirma();
65 65
         $idk = $this->getIDK();
66
-        if ($firma === false || $idk === false) {
66
+        if ($firma===false || $idk===false) {
67 67
             return false;
68 68
         }
69 69
         $pub_key = \sasco\LibreDTE\Sii::cert($idk);
70
-        if ($pub_key === false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) {
70
+        if ($pub_key===false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) {
71 71
             \sasco\LibreDTE\Log::write(
72 72
                 \sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA,
73 73
                 \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA)
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             );
99 99
             return false;
100 100
         }
101
-        return $plain === $plain_firmado;
101
+        return $plain===$plain_firmado;
102 102
     }
103 103
 
104 104
     /**
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     public function getCertificacion()
262 262
     {
263 263
         $idk = $this->getIDK();
264
-        return $idk ?  $idk === 100 : null;
264
+        return $idk ? $idk===100 : null;
265 265
     }
266 266
 
267 267
     /**
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
         }
278 278
         $fecha_autorizacion = $this->getFechaAutorizacion();
279 279
         $hoy = date('Y-m-d');
280
-        if ($fecha_autorizacion < '2018-07-01' and $hoy > '2018-12-31') {
280
+        if ($fecha_autorizacion<'2018-07-01' and $hoy>'2018-12-31') {
281 281
             return false;
282 282
         }
283
-        $vigencia = $fecha_autorizacion >= '2018-07-01' ? 6 : 18;
283
+        $vigencia = $fecha_autorizacion>='2018-07-01' ? 6 : 18;
284 284
         $d1 = new \DateTime($fecha_autorizacion);
285 285
         $d2 = new \DateTime($hoy);
286
-        $meses = $d1->diff($d2)->m + ($d1->diff($d2)->y*12);
287
-        return $meses <= $vigencia;
286
+        $meses = $d1->diff($d2)->m+($d1->diff($d2)->y * 12);
287
+        return $meses<=$vigencia;
288 288
     }
289 289
 
290 290
     /**
Please login to merge, or discard this patch.