Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verificarSiExisteLaClase() 0 7 2
A crear() 0 7 1
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