Passed
Branch master (0b4ab1)
by Esteban De La Fuente
74:02 queued 50:02
created

CertificateComponent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 93
ccs 0
cts 24
cp 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFakerWorker() 0 3 1
A createFake() 0 14 1
A getValidatorWorker() 0 3 1
A getLoaderWorker() 0 3 1
A getWorkers() 0 6 1
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Derafu: Biblioteca PHP (Núcleo).
7
 * Copyright (C) Derafu <https://www.derafu.org>
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 GNU
20
 * junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace Derafu\Lib\Core\Package\Prime\Component\Certificate;
26
27
use Derafu\Lib\Core\Foundation\Abstract\AbstractComponent;
28
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\CertificateComponentInterface;
29
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\FakerWorkerInterface;
30
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\LoaderWorkerInterface;
31
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\ValidatorWorkerInterface;
32
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Entity\Certificate;
33
34
/**
35
 * Servicio que gestiona todo lo asociado a certificados digitales (aka: firmas
36
 * electrónicas).
37
 */
38
class CertificateComponent extends AbstractComponent implements CertificateComponentInterface
39
{
40
    /**
41
     * Instancia que permite generar certificados autofirmados.
42
     *
43
     * @var FakerWorkerInterface
44
     */
45
    private FakerWorkerInterface $faker;
46
47
    /**
48
     * Instancia que permite cargar (crear) certificados a partir de sus datos.
49
     *
50
     * @var LoaderWorkerInterface
51
     */
52
    private LoaderWorkerInterface $loader;
53
54
    /**
55
     * Instancia que permite validar un certificado digital.
56
     *
57
     * @var ValidatorWorkerInterface
58
     */
59
    private ValidatorWorkerInterface $validator;
60
61
    /**
62
     * Constructor del componente.
63
     *
64
     * @param LoaderWorkerInterface $loader
65
     * @param ValidatorWorkerInterface $validator
66
     * @param FakerWorkerInterface $faker
67
     */
68
    public function __construct(
69
        FakerWorkerInterface $faker,
70
        LoaderWorkerInterface $loader,
71
        ValidatorWorkerInterface $validator,
72
    ) {
73
        $this->faker = $faker;
74
        $this->loader = $loader;
75
        $this->validator = $validator;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getWorkers(): array
82
    {
83
        return [
84
            'faker' => $this->faker,
85
            'loader' => $this->loader,
86
            'validator' => $this->validator,
87
        ];
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getFakerWorker(): FakerWorkerInterface
94
    {
95
        return $this->faker;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getLoaderWorker(): LoaderWorkerInterface
102
    {
103
        return $this->loader;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getValidatorWorker(): ValidatorWorkerInterface
110
    {
111
        return $this->validator;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function createFake(
118
        string $id,
119
        string $name,
120
        string $email
121
    ): Certificate {
122
        $faker = clone $this->faker;
123
124
        $faker->setSubject(
125
            serialNumber: $id,
126
            CN: $name,
127
            emailAddress: $email
128
        );
129
130
        return $faker->create();
131
    }
132
}
133