Test Failed
Push — master ( 49be21...52345e )
by Esteban De La Fuente
05:38
created

DocumentComponent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 11
dl 0
loc 13
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0

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
 * 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;
26
27
use Derafu\Lib\Core\Foundation\Abstract\AbstractComponent;
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\BatchProcessorWorkerInterface;
31
use libredte\lib\Core\Package\Billing\Component\Document\Contract\BuilderWorkerInterface;
32
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DispatcherWorkerInterface;
33
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentBagInterface;
34
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentBagManagerWorkerInterface;
35
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentComponentInterface;
36
use libredte\lib\Core\Package\Billing\Component\Document\Contract\LoaderWorkerInterface;
37
use libredte\lib\Core\Package\Billing\Component\Document\Contract\NormalizerWorkerInterface;
38
use libredte\lib\Core\Package\Billing\Component\Document\Contract\ParserWorkerInterface;
39
use libredte\lib\Core\Package\Billing\Component\Document\Contract\RendererWorkerInterface;
40
use libredte\lib\Core\Package\Billing\Component\Document\Contract\SanitizerWorkerInterface;
41
use libredte\lib\Core\Package\Billing\Component\Document\Contract\ValidatorWorkerInterface;
42
use libredte\lib\Core\Package\Billing\Component\Document\Support\DocumentBag;
43
use libredte\lib\Core\Package\Billing\Component\Identifier\Contract\CafInterface;
44
use libredte\lib\Core\Package\Billing\Component\Identifier\Contract\CafLoaderWorkerInterface;
45
use stdClass;
46
47
/**
48
 * Componente "billing.document".
49
 *
50
 * Este componente se encarga de la creación, manipulación y renderización de
51
 * los documentos tributarios.
52
 */
53
class DocumentComponent extends AbstractComponent implements DocumentComponentInterface
54
{
55 69
    public function __construct(
56
        private BatchProcessorWorkerInterface $batchProcessorWorker,
57
        private BuilderWorkerInterface $builderWorker,
58
        private DispatcherWorkerInterface $dispatcherWorker,
59
        private DocumentBagManagerWorkerInterface $documentBagManagerWorker,
60
        private LoaderWorkerInterface $loaderWorker,
61
        private NormalizerWorkerInterface $normalizerWorker,
62
        private ParserWorkerInterface $parserWorker,
63
        private RendererWorkerInterface $rendererWorker,
64
        private SanitizerWorkerInterface $sanitizerWorker,
65
        private ValidatorWorkerInterface $validatorWorker,
66
        private CafLoaderWorkerInterface $cafLoader
67
    ) {
68 69
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getWorkers(): array
74
    {
75
        return [
76
            'batch_processor' => $this->batchProcessorWorker,
77
            'builder' => $this->builderWorker,
78
            'dispatcher' => $this->dispatcherWorker,
79
            'document_bag_manager' => $this->documentBagManagerWorker,
80
            'loader' => $this->loaderWorker,
81
            'normalizer' => $this->normalizerWorker,
82
            'parser' => $this->parserWorker,
83
            'renderer' => $this->rendererWorker,
84
            'sanitizer' => $this->sanitizerWorker,
85
            'validator' => $this->validatorWorker,
86
        ];
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 1
    public function getBatchProcessorWorker(): BatchProcessorWorkerInterface
93
    {
94 1
        return $this->batchProcessorWorker;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 61
    public function getBuilderWorker(): BuilderWorkerInterface
101
    {
102 61
        return $this->builderWorker;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 5
    public function getDispatcherWorker(): DispatcherWorkerInterface
109
    {
110 5
        return $this->dispatcherWorker;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function getDocumentBagManagerWorker(): DocumentBagManagerWorkerInterface
117
    {
118
        return $this->documentBagManagerWorker;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 1
    public function getLoaderWorker(): LoaderWorkerInterface
125
    {
126 1
        return $this->loaderWorker;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function getNormalizerWorker(): NormalizerWorkerInterface
133
    {
134
        return $this->normalizerWorker;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 1
    public function getParserWorker(): ParserWorkerInterface
141
    {
142 1
        return $this->parserWorker;
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148 54
    public function getRendererWorker(): RendererWorkerInterface
149
    {
150 54
        return $this->rendererWorker;
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function getSanitizerWorker(): SanitizerWorkerInterface
157
    {
158
        return $this->sanitizerWorker;
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164 59
    public function getValidatorWorker(): ValidatorWorkerInterface
165
    {
166 59
        return $this->validatorWorker;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172 1
    public function bill(
173
        string|array|stdClass $data,
174
        string|CafInterface $caf = null,
175
        string|array|CertificateInterface $certificate = null,
176
        array|DataContainerInterface $options = null
177
    ): DocumentBagInterface {
178
        // Si el CAF es un string se debe construir el CAF.
179 1
        if (is_string($caf)) {
180
            $cafBag = $this->cafLoader->load($caf);
181
            $caf = $cafBag->getCaf();
182
        }
183
184
        // Crear contenedor del documento.
185 1
        $bag = new DocumentBag(
186 1
            inputData: $data,
187 1
            options: $options,
188 1
            caf: $caf,
0 ignored issues
show
Bug introduced by
It seems like $caf can also be of type string; however, parameter $caf of libredte\lib\Core\Packag...umentBag::__construct() does only seem to accept libredte\lib\Core\Packag...tract\CafInterface|null, 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

188
            /** @scrutinizer ignore-type */ caf: $caf,
Loading history...
189 1
            certificate: $certificate
0 ignored issues
show
Bug introduced by
It seems like $certificate can also be of type array; however, parameter $certificate of libredte\lib\Core\Packag...umentBag::__construct() does only seem to accept Derafu\Lib\Core\Package\...rtificateInterface|null, 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

189
            /** @scrutinizer ignore-type */ certificate: $certificate
Loading history...
190 1
        );
191
192
        // Parsear los datos de entrada pasados para crear el documento.
193 1
        $this->parserWorker->parse($bag);
194
195
        // Construir el documento tributario.
196 1
        $this->builderWorker->build($bag);
197
198
        // Entregar contenedor del documento.
199 1
        return $bag;
200
    }
201
}
202