Passed
Push — main ( a619f1...d1dc3f )
by Osvaldo
05:24
created

TipoDeJoin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 42
ccs 16
cts 16
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setJoin() 0 6 1
A __construct() 0 3 1
A esValido() 0 5 2
A estaVacio() 0 5 2
A sql() 0 3 1
1
<?php
2
namespace src\pdodatabase\elementos;
3
4
use Exception;
5
6
class TipoDeJoin
7
{
8
    private $_tiposValidos = [
9
        'inner' => 'INNER JOIN',
10
        'right' => 'RIGHT JOIN',
11
        'left' => 'LEFT JOIN',
12
        'full' => 'FULL JOIN'
13
    ];
14
15
    private $_join;
16
17 6
    public function __construct(string $join)
18
    {
19 6
        $this->_join = $this->setJoin($join);
20 4
    }
21
22 3
    public function sql(): string
23
    {
24 3
        return $this->_join;
25
    }
26
27 6
    public function setJoin(string $join): string
28
    {
29 6
        $this->estaVacio($join);
30 5
        $this->esValido($join);
31
32 4
        return $this->_tiposValidos[$join];
33
    }
34
35 6
    private function estaVacio(string $string): void
36
    {
37 6
        if(empty($string))
38
        {
39 1
            throw new Exception("Error Processing Request");
40
        }
41 5
    } 
42
43 5
    private function esValido(string $string): void
44
    {
45 5
        if(!array_key_exists($string, $this->_tiposValidos))
46
        {
47 1
            throw new Exception("Error Processing Request");
48
        }
49
    } 
50
}