Completed
Push — master ( 729958...215a1b )
by Esteban De La Fuente
01:40
created
lib/Sii/Factoring/Aec.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -87,10 +87,12 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function generar()
89 89
     {
90
-        if (!isset($this->cedido) or !isset($this->cesiones[0]))
91
-            return false;
92
-        if (!isset($this->caratula))
93
-            $this->setCaratula();
90
+        if (!isset($this->cedido) or !isset($this->cesiones[0])) {
91
+                    return false;
92
+        }
93
+        if (!isset($this->caratula)) {
94
+                    $this->setCaratula();
95
+        }
94 96
         // genear XML del envío
95 97
         $xmlEnvio = (new \sasco\LibreDTE\XML())->generate([
96 98
             'AEC' => [
@@ -137,8 +139,9 @@  discard block
 block discarded – undo
137 139
     public function enviar($retry = null, $gzip = false)
138 140
     {
139 141
         // generar XML que se enviará
140
-        if (!$this->xml_data)
141
-            $this->xml_data = $this->generar();
142
+        if (!$this->xml_data) {
143
+                    $this->xml_data = $this->generar();
144
+        }
142 145
         if (!$this->xml_data) {
143 146
             \sasco\LibreDTE\Log::write(
144 147
                 \sasco\LibreDTE\Estado::DOCUMENTO_ERROR_GENERAR_XML,
@@ -150,20 +153,24 @@  discard block
 block discarded – undo
150 153
             return false;
151 154
         }
152 155
         // validar schema del documento antes de enviar
153
-        if (!$this->schemaValidate())
154
-            return false;
156
+        if (!$this->schemaValidate()) {
157
+                    return false;
158
+        }
155 159
         // solicitar token
156 160
         $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($this->Firma);
157
-        if (!$token)
158
-            return false;
161
+        if (!$token) {
162
+                    return false;
163
+        }
159 164
         // enviar AEC
160 165
         $email = $this->caratula['MailContacto'];
161 166
         $emisor = $this->caratula['RutCedente'];
162 167
         $result = $this->enviarRTC($email, $emisor, $this->xml_data, $token, 10);
163
-        if ($result===false)
164
-            return false;
165
-        if (!is_numeric((string)$result->TRACKID))
166
-            return false;
168
+        if ($result===false) {
169
+                    return false;
170
+        }
171
+        if (!is_numeric((string)$result->TRACKID)) {
172
+                    return false;
173
+        }
167 174
         return (int)(string)$result->TRACKID;
168 175
     }
169 176
 
@@ -230,16 +237,19 @@  discard block
 block discarded – undo
230 237
         // enviar XML al SII
231 238
         for ($i = 0; $i < $retry; $i++) {
232 239
             $response = curl_exec($curl);
233
-            if ($response and $response != 'Error 500')
234
-                break;
240
+            if ($response and $response != 'Error 500') {
241
+                            break;
242
+            }
235 243
         }
236 244
         unlink($file);
237 245
         // verificar respuesta del envío y entregar error en caso que haya uno
238 246
         if (!$response or $response == 'Error 500') {
239
-            if (!$response)
240
-                \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, curl_error($curl)));
241
-            if ($response == 'Error 500')
242
-                \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_500, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_500));
247
+            if (!$response) {
248
+                            \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, curl_error($curl)));
249
+            }
250
+            if ($response == 'Error 500') {
251
+                            \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_500, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_500));
252
+            }
243 253
             return false;
244 254
         }
245 255
         // cerrar sesión curl
Please login to merge, or discard this patch.