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

Entre::setEntre()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 10
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
6
class Entre
7
{
8
    private $_entre;
9
    private $_datos;
10
11
    public function __construct(array $Entre)
12
    {
13
        $this->_entre = $this->setEntre($Entre);
14
    }
15
16
    public function donde(): string
17
    {
18
        return $this->_entre;
19
    }
20
21
    public function datos(): array
22
    {
23
        return $this->_datos;
24
    }
25
26
    private function setEntre(array $columnas): string
27
    {
28
        if(count($columnas) !== 3)
29
        {
30
            throw new Exception("Faltan elementos en la sentencia BETWEEN");   
31
        }
32
33
        foreach($columnas as $columna)
34
        {
35
            $this->alfaNumerico($columna);
36
        }
37
38
        $this->_datos = $this->setDatos($columnas);
39
        
40
        return ' WHERE '.$columnas[0].' BETWEEN ? AND ?';
41
    }
42
43
    private function alfaNumerico($string)
44
    {
45
        if(!ctype_alnum($string))
46
        {
47
            throw new Exception("Caracter invalido en el campo de la sentencia BETWEEN");
48
        }
49
    }
50
51
    private function setDatos(array $columnas): array
52
    {
53
        return array($columnas[1],$columnas[2]);
54
    }
55
}