JoinWhereAndOrderByLimit::crearJoin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
rs 10
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\WhereAnd;
19
use src\pdodatabase\sentencias\select\SentenciaJoinWhereOrdenYLimite;
20
21
class JoinWhereAndOrderByLimit 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 WhereAnd(
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 1
        return new ConsultaJoinWhereOrdenYLimite(
46 1
            new EjecutarConsultaConDatos(
47 1
                $conexion
48
            ),
49
            $sentencia
50
        );
51
    }
52
53 1
    private function obtenerJoins(array $array): array
54
    {
55 1
        foreach ($array['join'] as $value)
56
        {
57 1
            array_push($this->_joins, $this->crearJoin($value, $array['tabla']));           
58
59 1
            $this->multilplesJoin($value, $value['tabla']);
60
        }
61
62 1
        return $this->_joins;
63
    }
64
65 1
    private function crearJoin(array $array, string $tablaPadre): ElementosJoin
66
    {
67 1
        return new ElementosJoin(
68 1
            new TipoDeJoin($array['tipo']),
69 1
            new Tabla($tablaPadre),
70 1
            new Tabla($array['tabla']),
71 1
            new Campos($array['campos']),
72 1
            new NombreColumnaJoin($array['key'])
73
        );
74
    }
75
76 1
    private function multilplesJoin(array $value, string $tablaPadre): void
77
    {
78 1
        if(isset($value['join']))
79
        {
80 1
            foreach ($value['join'] as $value)
81
            {
82 1
               array_push($this->_joins, $this->crearJoin($value, $tablaPadre));
83
            }
84
85 1
            $this->multilplesJoin($value, $value['tabla']);
86
        }
87
    }
88
}