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

TipoDeJoin::setJoin()   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
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
}