Passed
Push — main ( bacfa2...24c5a0 )
by Osvaldo
07:23
created

Factory::crear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

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
rs 10
1
<?php
2
declare(strict_types=1);
3
namespace src;
4
use Exception;
5
use src\FactoryInterface;
6
7
Class Factory implements FactoryInterface
8
{
9
    private $_clase;
10
11
    public function crear(string $nombreDeLaClase, array $parametros): object
12
    {
13
        $this->_clase = $this->verificarSiExisteLaClase($nombreDeLaClase);
14
15
        $this->_clase = new $this->_clase;
16
        
17
        return $this->_clase->crear($parametros);
18
    }
19
20
    private function verificarSiExisteLaClase($nombreDeLaClase)
21
    {
22
        if(!class_exists($nombreDeLaClase))
23
        {
24
            throw new Exception("La clase no existe", 1);
25
        }
26
27
        return $nombreDeLaClase;
28
    }
29
}