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

Campos   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
wmc 8

4 Methods

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