DteEmitidos::verificarDteEmitido()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 1
b 0
f 0
nc 2
nop 8
dl 0
loc 30
ccs 0
cts 20
cp 0
crap 6
rs 9.7333

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * API Gateway: Cliente de API en PHP.
7
 * Copyright (C) API Gateway <https://www.apigateway.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la GNU Lesser General Public License (LGPL) publicada
11
 * por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia,
12
 * o (a su elección) cualquier versión posterior de la misma.
13
 *
14
 * Este programa se distribuye con la esperanza de que sea útil, pero SIN
15
 * GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16
 * PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la GNU Lesser General
17
 * Public License (LGPL) para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la GNU Lesser General Public License
20
 * (LGPL) junto a este programa. En caso contrario, consulte
21
 * <http://www.gnu.org/licenses/lgpl.html>.
22
 */
23
24
namespace apigatewaycl\api_client\sii;
25
26
use apigatewaycl\api_client\ApiBase;
27
use Psr\Http\Message\ResponseInterface;
28
29
/**
30
 * Módulo para interactuar con las opciones de Documentos Tributarios
31
 * Electrónicos (DTE) del SII.
32
 *
33
 * Para más información sobre la API, consulte la `documentación completa de
34
 * los DTE <https://developers.apigateway.cl/#8c113b9a-ea05-4981-9273-73e3f20ef991>`_.
35
 */
36
class DteEmitidos extends ApiBase
37
{
38
    /**
39
     * Cliente específico para gestionar DTE emitidos.
40
     *
41
     * Permite verificar la validez y autenticidad de un DTE emitido.
42
     *
43
     * @param array $credenciales Credenciales de autenticación.
44
     * @param string|null $token Token de autenticación para la API.
45
     * @param string|null $url URL base para la API.
46
     */
47
    public function __construct(
48
        array $credenciales,
49
        string $token = null,
50
        string $url = null
51
    ) {
52
        parent::__construct(
53
            credenciales: $credenciales,
54
            token: $token,
55
            url: $url
56
        );
57
    }
58
59
    /**
60
     * Verifica la validez de un DTE emitido.
61
     *
62
     * @param string $emisor RUT del emisor del DTE.
63
     * @param string $receptor RUT del receptor del DTE.
64
     * @param int $dte Tipo de DTE.
65
     * @param int $folio Número de folio del DTE.
66
     * @param string $fecha Fecha de emisión del DTE.
67
     * @param int $total Monto total del DTE.
68
     * @param string|null $firma Firma electrónica del DTE (opcional).
69
     * @param bool|null $certificacion Indica si la verificación es en ambiente
70
     * de certificación (opcional).
71
     * @return \Psr\Http\Message\ResponseInterface Respuesta JSON con el
72
     * resultado de la verificación del DTE.
73
     */
74
    public function verificarDteEmitido(
75
        string $emisor,
76
        string $receptor,
77
        int $dte,
78
        int $folio,
79
        string $fecha,
80
        int $total,
81
        string $firma = null,
82
        bool $certificacion = null
83
    ): ResponseInterface {
84
        $certificacion_flag = $certificacion ? 1 : 0;
85
        $url = sprintf(
86
            '/sii/dte/emitidos/verificar?certificacion=%d',
87
            $certificacion_flag
88
        );
89
        $body = [
90
            'auth' => $this->getAuthPass(),
91
            'dte' => [
92
                'emisor' => $emisor,
93
                'receptor' => $receptor,
94
                'dte' => $dte,
95
                'folio' => $folio,
96
                'fecha' => $fecha,
97
                'total' => $total,
98
                'firma' => $firma,
99
            ],
100
        ];
101
        $response = $this->post(resource: $url, data: $body);
102
103
        return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response could return the type null which is incompatible with the type-hinted return Psr\Http\Message\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
104
    }
105
}
106