Passed
Push — main ( 54e4df...1e4bb3 )
by Osvaldo
01:40
created

columnasRepetidas()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
use src\interfaces\ValidadorDeParametrosInterface;
6
7
class ValidadorDeParametrosWhereAndOthers implements ValidadorDeParametrosInterface
8
{
9
    private $_operadoresValidos = [
10
        '=',
11
        '>',
12
        '<',
13
        '>=',
14
        '<=',
15
        '<>',
16
        '!=',
17
        '!<',
18
        '!>',
19
        'LIKE',
20
        'IN',
21
    ];
22
23
    private $_datos;
24
25
    public function __construct(array $datos)
26
    {
27
        $this->_datos = $this->setDatos($datos);
28
    }
29
30
    public function datos(): array
31
    {
32
        return $this->_datos;
33
    }
34
35
    private function setDatos($array): array
36
    {
37
        $this->numeroDeElementosValido($array);
38
        $this->contieneValoresVacios($array);
39
        $this->columnasSonString($array);
40
        $this->operadorValido($array);
41
        $this->columnasRepetidas($array);
42
43
        return $array;
44
    }
45
46
    private function contieneValoresVacios($array): void
47
    {
48
        foreach ($array as $value)
49
        {
50
            if(empty($value))
51
            {
52
                throw new Exception("Error Processing Request");
53
            }
54
        }
55
    }
56
57
    private function columnasSonString($array): void
58
    {
59
        if(!is_string($array[0]) || !is_string($array[3]))
60
        {
61
            throw new Exception("Error Processing Request");
62
        }
63
    }
64
65
    private function numeroDeElementosValido($array): void
66
    {
67
        if(count($array) !== 6)
68
        {
69
            throw new Exception("Error Processing Request");
70
        }
71
    }
72
73
    private function operadorValido($array): void
74
    {
75
        if(!in_array($array[1], $this->_operadoresValidos) || !in_array($array[4], $this->_operadoresValidos))
76
        {
77
            throw new Exception("Error Processing Request");
78
        }
79
    }
80
81
    private function columnasRepetidas($array): void
82
    {
83
        if($array[0] == $array[3])
84
        {
85
            throw new Exception("Error Processing Request");
86
        }
87
    }
88
89
}