Factory::crear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
namespace src;
4
5
use Exception;
6
use src\FactoryInterface;
7
8
class Factory implements FactoryInterface
9
{
10
    private object $_clase;
11
    private string $_nombreDeLaClase;
12
13 2
    public function crear(string $nombreDeLaClase, ?array $parametros = array()): object
14
    {
15 2
        $this->_nombreDeLaClase = $this->verificarSiExisteLaClase($nombreDeLaClase);
16
17 1
        $this->_clase = new $this->_nombreDeLaClase;
18
        
19 1
        return $this->_clase->crear($parametros);
20
    }
21
    
22 2
    private function verificarSiExisteLaClase(string $nombreDeLaClase): string
23
    {
24 2
        if (!class_exists($nombreDeLaClase)) {
25 1
            throw new Exception("La clase no existe");
26
        }
27
28 1
        return $nombreDeLaClase;
29
    }
30
}
31