Passed
Push — master ( adfa60...f00212 )
by
unknown
09:50
created

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