Passed
Push — master ( d46be2...3039c3 )
by Esteban De La Fuente
03:19
created

FakerWorker::createAsString()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 67
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 5.4742

Importance

Changes 0
Metric Value
cc 5
eloc 35
c 0
b 0
f 0
nc 5
nop 0
dl 0
loc 67
ccs 33
cts 45
cp 0.7332
crap 5.4742
rs 9.0488

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Worker;
26
27
use Derafu\Lib\Core\Foundation\Abstract\AbstractWorker;
28
use Derafu\Lib\Core\Package\Prime\Component\Certificate\Contract\CertificateInterface;
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\Support\CertificateFaker;
32
33
/**
34
 * Clase que se encarga de generar certificados autofirmados (para pruebas).
35
 */
36
class FakerWorker extends AbstractWorker implements FakerWorkerInterface
37
{
38
    protected string $certificateFakerClass = CertificateFaker::class;
39
40 26
    public function __construct(
41
        private LoaderWorkerInterface $loader
42
    ) {
43 26
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 24
    public function create(
49
        ?string $id = null,
50
        ?string $name = null,
51
        ?string $email = null,
52
        ?string $password = null
53
    ): CertificateInterface {
54 24
        $class = $this->certificateFakerClass;
55 24
        $faker = new $class();
56
57 24
        $faker->setSubject(
58 24
            serialNumber: $id ?? '11222333-9',
59 24
            CN: $name ?? 'Daniel',
60 24
            emailAddress: $email ?? '[email protected]'
61 24
        );
62
63 22
        if ($password !== null) {
64
            $faker->setPassword($password);
65
        }
66
67 22
        $array = $faker->toArray();
68
69 22
        return $this->loader->createFromArray($array);
70
    }
71
}
72