Passed
Push — main ( 38eccc...fbb26c )
by Osvaldo
05:52
created

Join   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 58
ccs 28
cts 28
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A obtenerJoins() 0 10 2
A crearJoin() 0 8 1
A crear() 0 18 1
A multilplesJoin() 0 10 3
1
<?php
2
namespace src\factory;
3
4
use src\FactoryClassInterface;
5
use src\pdodatabase\conexion\CrearConexionBaseDeDatos;
6
use src\pdodatabase\consultas\select\ConsultaJoin;
7
use src\pdodatabase\ejecutar\EjecutarConsultaSinDatos;
8
use src\pdodatabase\elementos\Campos;
9
use src\pdodatabase\elementos\Join as ElementosJoin;
10
use src\pdodatabase\elementos\Joins;
11
use src\pdodatabase\elementos\NombreColumnaJoin;
12
use src\pdodatabase\elementos\Tabla;
13
use src\pdodatabase\elementos\TipoDeJoin;
14
use src\pdodatabase\sentencias\select\SentenciaJoin;
15
16
class Join implements FactoryClassInterface
17
{
18
    private $_joins = [];
19
20 1
    public function crear(array $array): ConsultaJoin
21
    {
22 1
        $conexion = new CrearConexionBaseDeDatos;
23 1
        $conexion = $conexion->crear([]);
24
25 1
        $sentencia = new SentenciaJoin(
26 1
            new Joins(
27 1
                new Tabla($array['tabla']),
28 1
                new Campos($array['campos']),
29 1
                $this->obtenerJoins($array)
30
            )
31
        );
32
        
33 1
        return new ConsultaJoin(
34 1
            new EjecutarConsultaSinDatos(
35 1
                $conexion
36
            ),
37
            $sentencia
38
        );
39
    }
40
41 1
    private function obtenerJoins(array $array): array
42
    {
43 1
        foreach ($array['join'] as $value)
44
        {
45 1
            array_push($this->_joins, $this->crearJoin($value, $array['tabla']));           
46
47 1
            $this->multilplesJoin($value, $value['tabla']);
48
        }
49
50 1
        return $this->_joins;
51
    }
52
53 1
    private function crearJoin(array $array, string $tablaPadre): ElementosJoin
54
    {
55 1
        return new ElementosJoin(
56 1
            new TipoDeJoin($array['tipo']),
57 1
            new Tabla($tablaPadre),
58 1
            new Tabla($array['tabla']),
59 1
            new Campos($array['campos']),
60 1
            new NombreColumnaJoin($array['key'])
61
        );
62
    }
63
64 1
    private function multilplesJoin(array $value, string $tablaPadre): void
65
    {
66 1
        if(isset($value['join']))
67
        {
68 1
            foreach ($value['join'] as $value)
69
            {
70 1
               array_push($this->_joins, $this->crearJoin($value, $tablaPadre));
71
            }
72
73 1
            $this->multilplesJoin($value, $value['tabla']);
74
        }
75
    }
76
}