Passed
Push — main ( 6ff268...46b174 )
by Osvaldo
01:43
created

Donde::alfaNumerico()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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->operadorValido($columnas[1]);
45
        
46
        $this->_datos = $this->setDatos($columnas);
47
48
        return ' WHERE '.$columnas[0].' '.$columnas[1].' ? ';
49
    }
50
51
    private function operadorValido($string)
52
    {
53
        if (!in_array($string, $this->_operadoresValidos))
54
        {
55
            throw new Exception("Comparador lógico invalido en el campo de la sentencia WHERE");
56
        }
57
    }
58
59
    private function setDatos(array $columnas): array
60
    {
61
        return array($columnas[2]);
62
    }
63
}