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

Campos   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 39
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A sql() 0 3 1
A camposNoEstaVacio() 0 12 4
A setCampos() 0 11 2
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
}