JoinWhereOrOrderByLimit::crear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 26
ccs 16
cts 16
cp 1
crap 1
rs 9.7333
1
<?php
2
namespace src\factory;
3
4
use src\FactoryClassInterface;
5
use src\pdodatabase\conexion\CrearConexionBaseDeDatos;
6
use src\pdodatabase\consultas\select\ConsultaJoinWhereOrdenYLimite;
7
use src\pdodatabase\ejecutar\EjecutarConsultaConDatos;
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\Limite;
12
use src\pdodatabase\elementos\NombreColumnaJoin;
13
use src\pdodatabase\elementos\Orden;
14
use src\pdodatabase\elementos\OrdenYLimite;
15
use src\pdodatabase\elementos\Tabla;
16
use src\pdodatabase\elementos\TipoDeJoin;
17
use src\pdodatabase\elementos\ValidadorDeParametrosWhereAndOthers;
18
use src\pdodatabase\elementos\WhereOr;
19
use src\pdodatabase\sentencias\select\SentenciaJoinWhereOrdenYLimite;
20
21
class JoinWhereOrOrderByLimit implements FactoryClassInterface
22
{
23
    private $_joins = [];
24
25 1
    public function crear(array $array): ConsultaJoinWhereOrdenYLimite
26
    {
27 1
        $conexion = new CrearConexionBaseDeDatos;
28 1
        $conexion = $conexion->crear([]);
29
30 1
        $sentencia = new SentenciaJoinWhereOrdenYLimite(
31 1
            new Joins(
32 1
                new Tabla($array['tabla']),
33 1
                new Campos($array['campos']),
34 1
                $this->obtenerJoins($array)
35
            ),
36 1
            new WhereOr(
37 1
                new ValidadorDeParametrosWhereAndOthers($array['where'])
38
            ),
39 1
            new OrdenYLimite(
40 1
                new Orden($array['order']),
41 1
                new Limite($array['limit'])
42
            )
43
            
44
        );
45
        
46 1
        return new ConsultaJoinWhereOrdenYLimite(
47 1
            new EjecutarConsultaConDatos(
48 1
                $conexion
49
            ),
50
            $sentencia
51
        );
52
    }
53
54 1
    private function obtenerJoins(array $array): array
55
    {
56 1
        foreach ($array['join'] as $value)
57
        {
58 1
            array_push($this->_joins, $this->crearJoin($value, $array['tabla']));           
59
60 1
            $this->multilplesJoin($value, $value['tabla']);
61
        }
62
63 1
        return $this->_joins;
64
    }
65
66 1
    private function crearJoin(array $array, string $tablaPadre): ElementosJoin
67
    {
68 1
        return new ElementosJoin(
69 1
            new TipoDeJoin($array['tipo']),
70 1
            new Tabla($tablaPadre),
71 1
            new Tabla($array['tabla']),
72 1
            new Campos($array['campos']),
73 1
            new NombreColumnaJoin($array['key'])
74
        );
75
    }
76
77 1
    private function multilplesJoin(array $value, string $tablaPadre): void
78
    {
79 1
        if(isset($value['join']))
80
        {
81 1
            foreach ($value['join'] as $value)
82
            {
83 1
               array_push($this->_joins, $this->crearJoin($value, $tablaPadre));
84
            }
85
86 1
            $this->multilplesJoin($value, $value['tabla']);
87
        }
88
    }
89
}