Test Failed
Push — master ( 87aaf6...f504c6 )
by Esteban De La Fuente
06:21 queued 01:53
created

SobreEnvio::getAutorizacionDte()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * LibreDTE: Biblioteca PHP (Núcleo).
7
 * Copyright (C) LibreDTE <https://www.libredte.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la Licencia Pública General Affero de GNU publicada por
11
 * la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o
12
 * (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 Licencia Pública
17
 * General Affero de GNU para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de
20
 * GNU junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace libredte\lib\Core\Package\Billing\Component\Document\Entity;
26
27
use Derafu\Lib\Core\Package\Prime\Component\Xml\Contract\XmlInterface;
28
use libredte\lib\Core\Package\Billing\Component\Document\Contract\SobreEnvioInterface;
29
use libredte\lib\Core\Package\Billing\Component\TradingParties\Contract\AutorizacionDteInterface;
30
use libredte\lib\Core\Package\Billing\Component\TradingParties\Entity\AutorizacionDte;
31
32
/**
33
 * Entidad que representa un sobre de envío de documentos al SII o intercambio
34
 * entre contribuyentes.
35
 */
36
class SobreEnvio implements SobreEnvioInterface
37
{
38
    /**
39
     * Instancia del documento XML asociado a los datos.
40
     *
41
     * @var XmlInterface
42
     */
43
    protected readonly XmlInterface $xmlDocument;
44
45
    /**
46
     * Constructor del sobre de documentos tributarios para su envío.
47
     *
48
     * @param XmlInterface $xmlDocument
49
     * @return void
50
     */
51 5
    public function __construct(XmlInterface $xmlDocument)
52
    {
53 5
        $this->xmlDocument = $xmlDocument;
0 ignored issues
show
Bug introduced by
The property xmlDocument is declared read-only in libredte\lib\Core\Packag...ument\Entity\SobreEnvio.
Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function __toString(): string
60
    {
61
        return $this->getId();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 5
    public function getXmlDocument(): XmlInterface
68
    {
69 5
        return $this->xmlDocument;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function saveXml(): string
76
    {
77
        return $this->xmlDocument->saveXml();
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getId(): string
84
    {
85
        return 'LibreDTE_SetDoc';
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 1
    public function getRutEmisor(): string
92
    {
93 1
        return $this->xmlDocument->query('//SetDTE/Caratula/RutEmisor');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->xmlDocumen...TE/Caratula/RutEmisor') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 1
    public function getRunMandatario(): string
100
    {
101 1
        return $this->xmlDocument->query('//SetDTE/Caratula/RutEnvia');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->xmlDocumen...DTE/Caratula/RutEnvia') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 1
    public function getRutReceptor(): string
108
    {
109 1
        return $this->xmlDocument->query('//SetDTE/Caratula/RutReceptor');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->xmlDocumen.../Caratula/RutReceptor') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 1
    public function getAutorizacionDte(): AutorizacionDteInterface
116
    {
117 1
        $fechaResolucion = $this->xmlDocument->query('//SetDTE/Caratula/FchResol');
118 1
        $numeroResolucion = (int) $this->xmlDocument->query('//SetDTE/Caratula/NroResol');
119
120 1
        return new AutorizacionDte($fechaResolucion, $numeroResolucion);
0 ignored issues
show
Bug introduced by
It seems like $fechaResolucion can also be of type array and null; however, parameter $fechaResolucion of libredte\lib\Core\Packag...acionDte::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
        return new AutorizacionDte(/** @scrutinizer ignore-type */ $fechaResolucion, $numeroResolucion);
Loading history...
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function getFechaFirma(): string
127
    {
128
        return $this->xmlDocument->query('//SetDTE/Caratula/TmstFirmaEnv');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->xmlDocumen...Caratula/TmstFirmaEnv') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function getResumen(): array
135
    {
136
        $SubTotDTE = $this->xmlDocument->query('//SetDTE/Caratula/SubTotDTE');
137
138
        return isset($SubTotDTE[0]) ? $SubTotDTE : [$SubTotDTE];
0 ignored issues
show
Bug Best Practice introduced by
The expression return IssetNode ? $SubTotDTE : array($SubTotDTE) could return the type string which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144 5
    public function getXmlDocumentos(): array
145
    {
146 5
        $documentos = [];
147
148 5
        $documentsNodes = $this->getXmlDocument()->getElementsByTagName('DTE');
149
150 5
        foreach ($documentsNodes as $documentNode) {
151 5
            $documentos[] = $documentNode->C14N();
152
        }
153
154 5
        return $documentos;
155
    }
156
}
157