Passed
Push — master ( c54296...9f2d90 )
by Esteban De La Fuente
06:57
created

DocumentBatch::getCertificate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
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\Support;
26
27
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\CertificateInterface;
28
use Derafu\Lib\Core\Support\Store\Contract\DataContainerInterface;
29
use Derafu\Lib\Core\Support\Store\DataContainer;
30
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentBatchInterface;
31
use libredte\lib\Core\Package\Billing\Component\TradingParties\Contract\EmisorInterface;
32
33
/**
34
 * Contenedor de datos para procesamiento en lote de documentos tributarios.
35
 *
36
 * Permite "mover" varios documentos, junto a otros datos asociados, por métodos
37
 * de manera sencilla y, sobre todo, extensible.
38
 */
39
class DocumentBatch implements DocumentBatchInterface
40
{
41
    /**
42
     * Ruta al archivo que contiene el lote de documentos que se deben procesar.
43
     *
44
     * @var string
45
     */
46
    private string $file;
47
48
    /**
49
     * Opciones para los workers asociados al procesamiento en lote de
50
     * documentos.
51
     *
52
     * Se definen los siguientes índices para las opciones:
53
     *
54
     *   - `batch_processor`: Opciones para el procesador en lote de documentos.
55
     *   - `builder`: Opciones para los constructores.
56
     *   - `normalizer`: Opciones para los normalizadores.
57
     *   - `parser`: Opciones para los analizadores sintácticos.
58
     *   - `renderer`: Opciones para los renderizadores.
59
     *   - `sanitizer`: Opciones para los sanitizadores.
60
     *   - `validator`: Opciones para los validadores.
61
     *
62
     * Se usarán las opciones por defecto en cada worker si no se indican los
63
     * índices en el arreglo $options.
64
     *
65
     * @var DataContainerInterface|null
66
     */
67
    private ?DataContainerInterface $options;
68
69
    /**
70
     * Reglas de esquema de las opciones del lote de documentos.
71
     *
72
     * El formato del esquema es el utilizado por
73
     * Symfony\Component\OptionsResolver\OptionsResolver.
74
     *
75
     * Acá solo se indicarán los índices que deben pueden existir en las
76
     * opciones. No se define el esquema de cada opción pues cada clase que
77
     * utilice estas opciones deberá resolver y validar sus propias opciones.
78
     *
79
     * @var array
80
     */
81
    protected array $optionsSchema = [
82
        'batch_processor' => [
83
            'types' => 'array',
84
            'default' => [],
85
        ],
86
        'builder' => [
87
            'types' => 'array',
88
            'default' => [],
89
        ],
90
        'normalizer' => [
91
            'types' => 'array',
92
            'default' => [],
93
        ],
94
        'parser' => [
95
            'types' => 'array',
96
            'default' => [],
97
        ],
98
        'renderer' => [
99
            'types' => 'array',
100
            'default' => [],
101
        ],
102
        'sanitizer' => [
103
            'types' => 'array',
104
            'default' => [],
105
        ],
106
        'validator' => [
107
            'types' => 'array',
108
            'default' => [],
109
        ],
110
    ];
111
112
    /**
113
     * Emisor del documento tributario.
114
     *
115
     * @var EmisorInterface|null
116
     */
117
    private ?EmisorInterface $emisor = null;
118
119
    /**
120
     * Certificado digital (firma electrónica) para la firma del documento.
121
     *
122
     * @var CertificateInterface|null
123
     */
124
    private ?CertificateInterface $certificate;
125
126
    /**
127
     * Constructor del lote.
128
     *
129
     * @param string $file
130
     * @param array|DataContainerInterface|null $options
131
     */
132 1
    public function __construct(
133
        string $file,
134
        array|DataContainerInterface|null $options = null
135
    ) {
136 1
        $this->file = $file;
137 1
        $this->setOptions($options);
138
    }
139
140
    /**
141
     * {@inheritDoc}
142
     */
143 1
    public function getFile(): string
144
    {
145 1
        return $this->file;
146
    }
147
148
    /**
149
     * {@inheritDoc}
150
     */
151 1
    public function setOptions(array|DataContainerInterface|null $options): static
152
    {
153 1
        if ($options === null) {
0 ignored issues
show
introduced by
The condition $options === null is always false.
Loading history...
154 1
            $options = [];
155
        }
156
157 1
        if (is_array($options)) {
0 ignored issues
show
introduced by
The condition is_array($options) is always true.
Loading history...
158 1
            $options = new DataContainer($options, $this->optionsSchema);
159
        }
160
161 1
        $this->options = $options;
162
163 1
        return $this;
164
    }
165
166
    /**
167
     * {@inheritDoc}
168
     */
169
    public function getOptions(): ?DataContainerInterface
170
    {
171
        return $this->options;
172
    }
173
174
    /**
175
     * {@inheritDoc}
176
     */
177 1
    public function setEmisor(?EmisorInterface $emisor): static
178
    {
179 1
        $this->emisor = $emisor;
180
181 1
        return $this;
182
    }
183
184
    /**
185
     * {@inheritDoc}
186
     */
187 1
    public function getEmisor(): ?EmisorInterface
188
    {
189 1
        return $this->emisor;
190
    }
191
192
    /**
193
     * {@inheritDoc}
194
     */
195 1
    public function setCertificate(?CertificateInterface $certificate): static
196
    {
197 1
        $this->certificate = $certificate;
198
199 1
        return $this;
200
    }
201
202
    /**
203
     * {@inheritDoc}
204
     */
205 1
    public function getCertificate(): ?CertificateInterface
206
    {
207 1
        return $this->certificate;
208
    }
209
}
210