Passed
Push — main ( 1c1b74...973229 )
by Osvaldo
05:20
created

ValidadorDeParametrosWhere   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 70
ccs 27
cts 27
cp 1
rs 10
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A datos() 0 3 1
A setDatos() 0 8 1
A __construct() 0 3 1
A numeroDeElementosValido() 0 5 2
A columnaEsString() 0 5 2
A contieneValoresVacios() 0 7 3
A operadorValido() 0 5 2
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
use src\interfaces\ValidadorDeParametrosInterface;
6
7
class ValidadorDeParametrosWhere 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 17
    public function __construct(array $datos)
26
    {
27 17
        $this->_datos = $this->setDatos($datos);
28 13
    }
29
30 13
    public function datos(): array
31
    {
32 13
        return $this->_datos;
33
    }
34
35 17
    public function setDatos($array): array
36
    {
37 17
        $this->numeroDeElementosValido($array);
38 16
        $this->contieneValoresVacios($array);
39 15
        $this->columnaEsString($array);
40 14
        $this->operadorValido($array);
41
42 13
        return $array;
43
    }
44
45 16
    private function contieneValoresVacios($array): void
46
    {
47 16
        foreach ($array as $value)
48
        {
49 16
            if(empty($value))
50
            {
51 1
                throw new Exception("Error Processing Request");
52
            }
53
        }
54 15
    }
55
56 17
    private function numeroDeElementosValido($array): void
57
    {
58 17
        if(count($array) !== 3)
59
        {
60 1
            throw new Exception("Error Processing Request");
61
        }
62 16
    }
63
64 14
    private function operadorValido($array): void
65
    {
66 14
        if(!in_array($array[1], $this->_operadoresValidos))
67
        {
68 1
            throw new Exception("Error Processing Request");
69
        }
70 13
    }
71
72 15
    private function columnaEsString($array): void
73
    {
74 15
        if(!is_string($array[0]))
75
        {
76 1
            throw new Exception("Error Processing Request");
77
        }
78
    }
79
}