ValidadorDeParametrosWhereBetween::__construct()   A
last analyzed

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 1
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 ValidadorDeParametrosWhereBetween implements ValidadorDeParametrosInterface
8
{
9
    private $_datos;
10
11 32
    public function __construct(array $datos)
12
    {
13 32
        $this->_datos = $this->setDatos($datos);
14 28
    }
15
16 28
    public function datos(): array
17
    {
18 28
        return $this->_datos;
19
    }
20
21 32
    private function setDatos(array $array): array
22
    {
23 32
        $this->numeroDeElementosValido($array);
24 31
        $this->columnaEsString($array);       
25 30
        $this->valoresNoSonIguales($array);
26 29
        $this->contieneValoresVacios($array);
27
28 28
        return $array;
29
    }
30
31 29
    private function contieneValoresVacios($array): void
32
    {
33 29
        foreach ($array as $value)
34
        {
35 29
            if(empty($value))
36
            {
37 1
                throw new Exception("Error Processing Request");
38
            }
39
        }
40 28
    }
41
42 30
    private function valoresNoSonIguales($array): void
43
    {
44 30
        if($array[1] == $array[2])
45
        {
46 1
            throw new Exception("Error Processing Request");
47
        }
48 29
    }
49
50 32
    private function numeroDeElementosValido($array): void
51
    {
52 32
        if(count($array) !== 3)
53
        {
54 1
            throw new Exception("Error Processing Request");
55
        }
56 31
    }
57
58 31
    private function columnaEsString($array): void
59
    {
60 31
        if(!is_string($array[0]))
61
        {
62 1
            throw new Exception("Error Processing Request");
63
        }
64
    }
65
}