Total Complexity | 10 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
||
72 | } |
||
73 | } |