Passed
Push — main ( 973229...53c627 )
by Osvaldo
05:17
created

ValidadorDeParametrosWhereAndOthers::datos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 10
    public function __construct(array $datos)
26
    {
27 10
        $this->_datos = $this->setDatos($datos);
28 6
    }
29
30 6
    public function datos(): array
31
    {
32 6
        return $this->_datos;
33
    }
34
35 10
    private function setDatos($array): array
36
    {
37 10
        $this->numeroDeElementosValido($array);
38 9
        $this->contieneValoresVacios($array);
39 8
        $this->columnasSonString($array);
40 7
        $this->operadorValido($array);
41
42 6
        return $array;
43
    }
44
45 9
    private function contieneValoresVacios($array): void
46
    {
47 9
        foreach ($array as $value)
48
        {
49 9
            if(empty($value))
50
            {
51 1
                throw new Exception("Error Processing Request");
52
            }
53
        }
54 8
    }
55
56 8
    private function columnasSonString($array): void
57
    {
58 8
        if(!is_string($array[0]) || !is_string($array[3]))
59
        {
60 1
            throw new Exception("Error Processing Request");
61
        }
62 7
    }
63
64 10
    private function numeroDeElementosValido($array): void
65
    {
66 10
        if(count($array) !== 6)
67
        {
68 1
            throw new Exception("Error Processing Request");
69
        }
70 9
    }
71
72 7
    private function operadorValido($array): void
73
    {
74 7
        if(!in_array($array[1], $this->_operadoresValidos) || !in_array($array[4], $this->_operadoresValidos))
75
        {
76 1
            throw new Exception("Error Processing Request");
77
        }
78 6
    }
79
80
}