Passed
Push — main ( 6cdb6f...ad9b5a )
by Osvaldo
05:28
created

JoinOrderBy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

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