JoinWhereLimit   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 62
ccs 31
cts 31
cp 1
rs 10
wmc 7

4 Methods

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