Completed
Push — master ( 223ada...4e5c26 )
by Esteban De La Fuente
02:01
created

ingresarAceptacionReclamoDoc()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 5
1
<?php
2
3
/**
4
 * LibreDTE
5
 * Copyright (C) SASCO SpA (https://sasco.cl)
6
 *
7
 * Este programa es software libre: usted puede redistribuirlo y/o
8
 * modificarlo bajo los términos de la Licencia Pública General Affero de GNU
9
 * publicada por la Fundación para el Software Libre, ya sea la versión
10
 * 3 de la Licencia, o (a su elección) cualquier versión posterior de la
11
 * misma.
12
 *
13
 * Este programa se distribuye con la esperanza de que sea útil, pero
14
 * SIN GARANTÍA ALGUNA; ni siquiera la garantía implícita
15
 * MERCANTIL o de APTITUD PARA UN PROPÓSITO DETERMINADO.
16
 * Consulte los detalles de la Licencia Pública General Affero de GNU para
17
 * obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de GNU
20
 * junto a este programa.
21
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
22
 */
23
24
namespace sasco\LibreDTE\Sii;
25
26
/**
27
 * Clase con las acciones asociadas al registro de compras y ventas del SII
28
 * Este registro reemplaza a LibroCompraVenta (IECV)
29
 * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
30
 * @version 2017-09-11
31
 */
32
class RegistroCompraVenta
33
{
34
35
    private static $config = [
36
        'wsdl' => [
37
            'https://ws1.sii.cl/WSREGISTRORECLAMODTE/registroreclamodteservice?wsdl',
38
            'https://ws2.sii.cl/WSREGISTRORECLAMODTECERT/registroreclamodteservice?wsdl',
39
        ],
40
        'servidor' => ['ws1', 'ws2'], ///< servidores 0: producción, 1: certificación
41
    ];
42
43
    public static $dtes = [
44
        33 => 'Factura electrónica',
45
        34 => 'Factura no afecta o exenta electrónica',
46
        43 => 'Liquidación factura electrónica',
47
    ]; ///< Documentos que tienen acuse de recibo
48
49
    public static $acciones = [
50
        'ERM' => 'Otorga recibo de mercaderías o servicios',
51
        'ACD' => 'Acepta contenido del documento',
52
        'RCD' => 'Reclamo al contenido del documento',
53
        'RFP' => 'Reclamo por falta parcial de mercaderías',
54
        'RFT' => 'Reclamo por falta total de mercaderías',
55
    ]; ///< Posibles acciones a que tiene asociadas un DTE
56
57
    public static $eventos = [
58
        'A' => 'No reclamado en plazo (recepción automática)',
59
        'C' => 'Recibo otorgado por el receptor',
60
        'P' => 'Forma de pago al contado',
61
        'R' => 'Reclamado',
62
    ];
63
64
    public static $tipo_transacciones = [
65
        1 => 'Compras del giro',
66
        2 => 'Compras en supermercados o comercios similares',
67
        3 => 'Adquisición de bienes raíces',
68
        4 => 'Compra de activo fijo',
69
        5 => 'Compras con IVA uso común',
70
        6 => 'Compras sin derecho a crédito',
71
    ]; ///< Tipos de transacciones o caracterizaciones/clasificaciones de las compras
72
73
    public static $estados_ok = [
74
        7,  // Evento registrado previamente
75
        8,  // Pasados 8 días después de la recepción no es posible registrar reclamos o eventos
76
        27, // No se puede registrar un evento (acuse de recibo, reclamo o aceptación de contenido) de un DTE pagado al contado o gratuito
77
    ]; ///< Código de estado de respuesta de la asignación de estado que son considerados como OK
78
79
    private $token; ///< Token que se usará en la sesión de consultas al RCV
80
81
    /**
82
     * Constructor, obtiene el token de la sesión y lo guarda
83
     * @param Firma Objeto con la firma electrónica
84
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
85
     * @version 2017-08-28
86
     */
87
    public function __construct(\sasco\LibreDTE\FirmaElectronica $Firma)
88
    {
89
        $this->token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma);
0 ignored issues
show
Documentation introduced by
$Firma is of type object<sasco\LibreDTE\FirmaElectronica>, but the function expects a object<sasco\LibreDTE\Sii\objeto>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
        if (!$this->token) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->token of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
91
            throw new \Exception('No fue posible obtener el token para la sesión del RCV');
92
        }
93
    }
94
95
    /**
96
     * Método que ingresa una acción al registro de compr/venta en el SII
97
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
98
     * @version 2017-08-29
99
     */
100 View Code Duplication
    public function ingresarAceptacionReclamoDoc($rut, $dv, $dte, $folio, $accion)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        // ingresar acción al DTE
103
        $r = $this->request('ingresarAceptacionReclamoDoc', [
0 ignored issues
show
Documentation introduced by
'ingresarAceptacionReclamoDoc' is of type string, but the function expects a object<sasco\LibreDTE\Sii\Nombre>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('rutEmisor' => $ru...'accionDoc' => $accion) is of type array<string,?,{"rutEmis...":"?","accionDoc":"?"}>, but the function expects a object<sasco\LibreDTE\Sii\Argumentos>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
104
            'rutEmisor' => $rut,
105
            'dvEmisor' => $dv,
106
            'tipoDoc' => $dte,
107
            'folio' => $folio,
108
            'accionDoc' => $accion,
109
        ]);
110
        // si no se pudo recuperar error
111
        if ($r===false) {
112
            return false;
113
        }
114
        // entregar resultado del ingreso
115
        return [
116
            'codigo' => $r->codResp,
117
            'glosa' => $r->descResp,
118
        ];
119
    }
120
121
    /**
122
     * Método que entrega los eventos asociados a un DTE
123
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
124
     * @version 2017-08-28
125
     */
126
    public function listarEventosHistDoc($rut, $dv, $dte, $folio)
127
    {
128
        // consultar eventos del DTE
129
        $r = $this->request('listarEventosHistDoc', [
0 ignored issues
show
Documentation introduced by
'listarEventosHistDoc' is of type string, but the function expects a object<sasco\LibreDTE\Sii\Nombre>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('rutEmisor' => $ru...dte, 'folio' => $folio) is of type array<string,?,{"rutEmis...oDoc":"?","folio":"?"}>, but the function expects a object<sasco\LibreDTE\Sii\Argumentos>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
            'rutEmisor' => $rut,
131
            'dvEmisor' => $dv,
132
            'tipoDoc' => $dte,
133
            'folio' => $folio,
134
        ]);
135
        // si no se pudo recuperar error
136
        if ($r===false) {
137
            return false;
138
        }
139
        // si hubo error informar
140
        if (!in_array($r->codResp, [8, 15, 16])) {
141
            throw new \Exception($r->descResp);
142
        }
143
        // entregar eventos del DTE
144
        $eventos = [];
145
        if (!empty($r->listaEventosDoc)) {
146
            if (!is_array($r->listaEventosDoc)) {
147
                $r->listaEventosDoc = [$r->listaEventosDoc];
148
            }
149
            foreach ($r->listaEventosDoc as $evento) {
150
                $eventos[] = [
151
                    'codigo' => $evento->codEvento,
152
                    'glosa' => $evento->descEvento,
153
                    'responsable' => $evento->rutResponsable.'-'.$evento->dvResponsable,
154
                    'fecha' => $evento->fechaEvento,
155
                ];
156
            }
157
        }
158
        return $eventos;
159
    }
160
161
    /**
162
     * Entrega información de cesión para el DTE, si es posible o no cederlo
163
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
164
     * @version 2017-08-28
165
     */
166 View Code Duplication
    public function consultarDocDteCedible($rut, $dv, $dte, $folio)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
    {
168
        // consultar eventos del DTE
169
        $r = $this->request('consultarDocDteCedible', [
0 ignored issues
show
Documentation introduced by
'consultarDocDteCedible' is of type string, but the function expects a object<sasco\LibreDTE\Sii\Nombre>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('rutEmisor' => $ru...dte, 'folio' => $folio) is of type array<string,?,{"rutEmis...oDoc":"?","folio":"?"}>, but the function expects a object<sasco\LibreDTE\Sii\Argumentos>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
170
            'rutEmisor' => $rut,
171
            'dvEmisor' => $dv,
172
            'tipoDoc' => $dte,
173
            'folio' => $folio,
174
        ]);
175
        // si no se pudo recuperar error
176
        if ($r===false) {
177
            return false;
178
        }
179
        // entregar información de cesión para el DTE
180
        return [
181
            'codigo' => $r->codResp,
182
            'glosa' => $r->descResp,
183
        ];
184
    }
185
186
    /**
187
     *
188
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
189
     * @version 2017-09-21
190
     */
191
    public function consultarFechaRecepcionSii($rut, $dv, $dte, $folio)
192
    {
193
        // consultar eventos del DTE
194
        $r = $this->request('consultarFechaRecepcionSii', [
0 ignored issues
show
Documentation introduced by
'consultarFechaRecepcionSii' is of type string, but the function expects a object<sasco\LibreDTE\Sii\Nombre>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('rutEmisor' => $ru...dte, 'folio' => $folio) is of type array<string,?,{"rutEmis...oDoc":"?","folio":"?"}>, but the function expects a object<sasco\LibreDTE\Sii\Argumentos>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
195
            'rutEmisor' => $rut,
196
            'dvEmisor' => $dv,
197
            'tipoDoc' => $dte,
198
            'folio' => $folio,
199
        ]);
200
        // si no se pudo recuperar error
201
        if (!$r) {
202
            return false;
203
        }
204
        // armar y entregar fecha
205
        list($dia, $hora) = explode(' ', $r);
206
        list($d, $m, $Y) = explode('-', $dia);
207
        return $Y.'-'.$m.'-'.$d.' '.$hora;
208
    }
209
210
    /**
211
     * Método para realizar una solicitud al servicio web del SII
212
     * @param request Nombre de la función que se ejecutará en el servicio web
213
     * @param args Argumentos que se pasarán al servicio web
214
     * @param retry Intentos que se realizarán como máximo para obtener respuesta
215
     * @return Objeto o String con la respuesta (depende servicio web)
216
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
217
     * @version 2020-02-12
218
     */
219
    private function request($request, $args, $retry = 10)
220
    {
221
        $options = ['keep_alive' => false];
222 View Code Duplication
        if (!\sasco\LibreDTE\Sii::getVerificarSSL()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
223
            if (\sasco\LibreDTE\Sii::getAmbiente()==\sasco\LibreDTE\Sii::PRODUCCION) {
224
                $msg = \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_SSL_SIN_VERIFICAR);
225
                \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_SSL_SIN_VERIFICAR, $msg, LOG_WARNING);
0 ignored issues
show
Documentation introduced by
$msg is of type integer|string, but the function expects a object<sasco\LibreDTE\Mensaje>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
LOG_WARNING is of type integer, but the function expects a object<sasco\LibreDTE\Gravedad>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
            }
227
            $options['stream_context'] = stream_context_create([
228
                'ssl' => [
229
                    'verify_peer' => false,
230
                    'verify_peer_name' => false,
231
                    'allow_self_signed' => true
232
                ]
233
            ]);
234
        }
235
        // buscar WSDL
236
        $ambiente = \sasco\LibreDTE\Sii::getAmbiente();
237
        $wsdl = dirname(dirname(dirname(__FILE__))).'/wsdl/'.self::$config['servidor'][$ambiente].'/registroreclamodteservice.xml';
238
        if (!file_exists($wsdl)) {
239
            $wsdl = self::$config['wsdl'][$ambiente];
240
        }
241
        // crear el cliente SOAP
242
        try {
243
            $soap = new \SoapClient($wsdl, $options);
244
            $soap->__setCookie('TOKEN', $this->token);
245
        } catch (\Exception $e) {
246
            $msg = $e->getMessage();
247 View Code Duplication
            if (isset($e->getTrace()[0]['args'][1]) and is_string($e->getTrace()[0]['args'][1])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
248
                $msg .= ': '.$e->getTrace()[0]['args'][1];
249
            }
250
            \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, $msg));
0 ignored issues
show
Documentation introduced by
\sasco\LibreDTE\Estado::...QUEST_ERROR_SOAP, $msg) is of type integer|string, but the function expects a object<sasco\LibreDTE\Mensaje>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
251
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by sasco\LibreDTE\Sii\RegistroCompraVenta::request of type sasco\LibreDTE\Sii\objeto.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
252
        }
253
        // hacer consultas al SII
254
        for ($i=0; $i<$retry; $i++) {
255
            try {
256
                $body = call_user_func_array([$soap, $request], $args);
257
                break;
258
            } catch (\Exception $e) {
259
                $msg = $e->getMessage();
260 View Code Duplication
                if (isset($e->getTrace()[0]['args'][1]) and is_string($e->getTrace()[0]['args'][1])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
261
                    $msg .= ': '.$e->getTrace()[0]['args'][1];
262
                }
263
                \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, $msg));
0 ignored issues
show
Documentation introduced by
\sasco\LibreDTE\Estado::...QUEST_ERROR_SOAP, $msg) is of type integer|string, but the function expects a object<sasco\LibreDTE\Mensaje>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
264
                $body = null;
265
            }
266
        }
267 View Code Duplication
        if ($body===null) {
0 ignored issues
show
Bug introduced by
The variable $body does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
            \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::REQUEST_ERROR_BODY, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::REQUEST_ERROR_BODY, $wsdl, $retry));
0 ignored issues
show
Documentation introduced by
\sasco\LibreDTE\Estado::...OR_BODY, $wsdl, $retry) is of type integer|string, but the function expects a object<sasco\LibreDTE\Mensaje>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
269
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by sasco\LibreDTE\Sii\RegistroCompraVenta::request of type sasco\LibreDTE\Sii\objeto.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
270
        }
271
        return $body;
272
    }
273
274
}
275