Passed
Push — main ( 67a4aa...1c1b74 )
by Osvaldo
05:10
created

Update::setDatos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
use src\interfaces\WhereInterface;
6
7
class Update
8
{
9
    private $_datos;
10
    private $_where;
11
12 6
    public function __construct(array $datos, WhereInterface $whereInterface)
13
    {
14 6
        $this->_datos = $this->setDatos($datos);
15 5
        $this->_where = $whereInterface;
16 5
    }
17
18 3
    public function sql(): string
19
    {
20 3
        return $this->armarConsulta($this->_datos).' '.$this->_where->sql();
21
    }
22
23 3
    public function datos(): array
24
    {
25 3
        $array = $this->_datos;
26
27 3
        foreach ($this->_where->datos() as $value)
28
        {
29 3
            array_push($array, $value);
30
        }
31
32 3
        return $array;
33
    }
34
35 6
    private function setDatos(array $array): array
36
    {
37 6
        $this->estaVacio($array);
38 5
        $this->columnaVacia($array);
39
40 5
        return $array;
41
    }
42
43 6
    private function estaVacio(array $array): void
44
    {
45 6
        if (count($array) == 0)
46
        {
47 1
            throw new Exception("Error Processing Request");
48
        }
49 5
    }
50
51 5
    private function columnaVacia(array $array): void
52
    {
53 5
        foreach ($array as $key => $value)
54
        {
55 5
            if(empty($key))
56
            {
57
                throw new Exception("Error Processing Request");   
58
            }
59
        }
60 5
    }
61
62 3
    private function armarConsulta(array $array): string
63
    {
64 3
        $set = "";
65
66 3
		$values = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $values is dead and can be removed.
Loading history...
67
68 3
		foreach ($array as $key => $value)
69
		{
70 3
			$set = $set.$key. ' = ?,';
71
		}
72
73 3
		return trim($set, ',');  
74
    }
75
}