Passed
Push — main ( c8f39c...1a4746 )
by Osvaldo
02:04
created

Campos::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
6
class Campos
7
{
8
    private $_campos;
9
10
    public function __construct(array $array)
11
    {
12
        $this->_campos = $this->setCampos($array);
13
    }
14
15
    public function sql(): string
16
    {
17
        return $this->_campos;
18
    }
19
20
    private function setCampos(array $array): string
21
    {
22
        $this->camposNoEstaVacio($array);
23
24
        $campos = '';
25
        foreach($array as $arr)
26
        {
27
            $campos = $arr.','.$campos;
28
        }
29
30
        return trim($campos, ',');
31
    }
32
33
    private function camposNoEstaVacio(array $array): void
34
    {
35
        if(count($array) == 0)
36
        {
37
            throw new Exception("Error Processing Request");  
38
        }
39
40
        foreach ($array as $value)
41
        {
42
            if(empty($value))
43
            {
44
                throw new Exception("Error Processing Request");
45
            }
46
        }
47
    }
48
}