JoinWhereOrderByLimit   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 65
ccs 33
cts 33
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A crear() 0 25 1
A multilplesJoin() 0 10 3
A obtenerJoins() 0 10 2
A crearJoin() 0 8 1
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\ValidadorDeParametrosWhere;
18
use src\pdodatabase\elementos\Where;
19
use src\pdodatabase\sentencias\select\SentenciaJoinWhereOrdenOLimite;
20
use src\pdodatabase\sentencias\select\SentenciaJoinWhereOrdenYLimite;
21
22
class JoinWhereOrderByLimit implements FactoryClassInterface
23
{
24
    private $_joins = [];
25
26 1
    public function crear(array $array): ConsultaJoinWhereOrdenYLimite
27
    {
28 1
        $conexion = new CrearConexionBaseDeDatos;
29 1
        $conexion = $conexion->crear([]);
30
31 1
        $sentencia = new SentenciaJoinWhereOrdenYLimite(
32 1
            new Joins(
33 1
                new Tabla($array['tabla']),
34 1
                new Campos($array['campos']),
35 1
                $this->obtenerJoins($array)
36
            ),
37 1
            new Where(
38 1
                new ValidadorDeParametrosWhere($array['where'])
39
            ),
40 1
            new OrdenYLimite(
41 1
                new Orden($array['order']),
42 1
                new Limite($array['limit'])
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
}