Passed
Push — main ( f2df15...8d7bb5 )
by Osvaldo
09:13
created

Donde   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 66
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDatos() 0 3 1
A operadorValido() 0 5 2
A __construct() 0 3 1
A setDonde() 0 14 2
A donde() 0 3 1
A datos() 0 3 1
A alfaNumerico() 0 5 2
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
6
class Donde
7
{
8
    private $_donde;
9
    private $_datos;
10
    private $_operadoresValidos = [
11
        '=',
12
        '>',
13
        '<',
14
        '>=',
15
        '<=',
16
        '<>',
17
        '!=',
18
        '!<',
19
        '!>',
20
    ];
21
22
    public function __construct(array $Donde)
23
    {
24
        $this->_donde = $this->setDonde($Donde);
25
    }
26
27
    public function donde(): string
28
    {
29
        return $this->_donde;
30
    }
31
32
    public function datos(): array
33
    {
34
        return $this->_datos;
35
    }
36
37
    private function setDonde(array $columnas): string
38
    {
39
        if(count($columnas) !== 3)
40
        {
41
            throw new Exception("Elementos faltantes o sobrantes en la sentencia WHERE", 1);
42
        }
43
        
44
        $this->alfaNumerico($columnas[0]);
45
        $this->operadorValido($columnas[1]);
46
        $this->alfaNumerico($columnas[2]);
47
        
48
        $this->_datos = $this->setDatos($columnas);
49
50
        return ' WHERE '.$columnas[0].' '.$columnas[1].' ? ';
51
    }
52
53
    private function alfaNumerico($string)
54
    {
55
        if(!ctype_alnum($string))
56
        {
57
            throw new Exception("Caracter invalido en el campo de la sentencia WHERE");
58
        }
59
    }
60
61
    private function operadorValido($string)
62
    {
63
        if (!in_array($string, $this->_operadoresValidos))
64
        {
65
            throw new Exception("Comparador lógico invalido en el campo de la sentencia WHERE");
66
        }
67
    }
68
69
    private function setDatos(array $columnas): array
70
    {
71
        return array($columnas[2]);
72
    }
73
}