SanitizerWorker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
dl 0
loc 32
ccs 8
cts 11
cp 0.7272
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sanitize() 0 18 2
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\Worker;
26
27
use Derafu\Backbone\Abstract\AbstractWorker;
28
use Derafu\Backbone\Attribute\Worker;
29
use Derafu\Backbone\Trait\StrategiesAwareTrait;
30
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentBagInterface;
31
use libredte\lib\Core\Package\Billing\Component\Document\Contract\SanitizerStrategyInterface;
32
use libredte\lib\Core\Package\Billing\Component\Document\Contract\SanitizerWorkerInterface;
33
use libredte\lib\Core\Package\Billing\Component\Document\Exception\SanitizerException;
34
35
/**
36
 * Clase para los sanitizadores.
37
 */
38
#[Worker(name: 'sanitizer', component: 'document', package: 'billing')]
39
class SanitizerWorker extends AbstractWorker implements SanitizerWorkerInterface
40
{
41
    use StrategiesAwareTrait;
42
43 53
    public function __construct(
44
        iterable $strategies = []
45
    ) {
46 53
        $this->setStrategies($strategies);
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 53
    public function sanitize(DocumentBagInterface $bag): array
53
    {
54
        // Si no hay tipo de documento no se podrá sanitizar.
55 53
        if (!$bag->getTipoDocumento()) {
56
            throw new SanitizerException(
57
                'No es posible sanitizar sin un TipoDocumento en la $bag.'
58
            );
59
        }
60
61
        // Buscar la estrategia para sanitizar el tipo de documento tributario.
62 53
        $strategy = $this->getStrategy($bag->getTipoDocumento()->getAlias());
0 ignored issues
show
Bug introduced by
It seems like $bag->getTipoDocumento()->getAlias() can also be of type null; however, parameter $strategy of libredte\lib\Core\Packag...erWorker::getStrategy() 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

62
        $strategy = $this->getStrategy(/** @scrutinizer ignore-type */ $bag->getTipoDocumento()->getAlias());
Loading history...
63 53
        assert($strategy instanceof SanitizerStrategyInterface);
64
65
        // Sanitizar el documento usando la estrategia.
66 53
        $sanitizedData = $strategy->sanitize($bag);
67
68
        // Entregar los datos sanitizados.
69 53
        return $sanitizedData;
70
    }
71
}
72