Join::on()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Muffin\Queries\Snippets\Builders;
4
5
use Muffin\Queries\Snippets;
6
7
trait Join
8
{
9
    protected
10
        $joins = array();
11
12 5
    public function innerJoin($table, $alias = null)
13
    {
14 5
        $this->joins[] = new Snippets\Joins\InnerJoin($table, $alias);
15
16 5
        return $this;
17
    }
18
19 4
    public function leftJoin($table, $alias = null)
20
    {
21 4
        $this->joins[] = new Snippets\Joins\LeftJoin($table, $alias);
22
23 4
        return $this;
24
    }
25
26 4
    public function rightJoin($table, $alias = null)
27
    {
28 4
        $this->joins[] = new Snippets\Joins\RightJoin($table, $alias);
29
30 4
        return $this;
31
    }
32
33 10
    public function on($leftColumn, $rightColumn)
34 1
    {
35 10
        $join = $this->getLastJoin();
36 9
        $join->on($leftColumn, $rightColumn);
37
38 9
        return $this;
39
    }
40
41 2
    public function using($column)
42
    {
43 2
        $join = $this->getLastJoin();
44 2
        $join->using($column);
45
46 2
        return $this;
47
    }
48
49 30
    protected function buildJoin()
50
    {
51 30
        $joins = array();
52
53 30
        foreach($this->joins as $innerJoin)
54
        {
55 9
            $joins[] = $innerJoin->toString();
56 30
        }
57
58 30
        return implode(' ', $joins);
59
    }
60
61 10
    private function getLastJoin()
62
    {
63 10
        $lastJoins = end($this->joins);
64
65 10
        if(! $lastJoins instanceof Snippets\Join)
66 10
        {
67 1
            throw new \LogicException('Erreur dans la récupération de la dernière jointure');
68
        }
69
70 9
        return $lastJoins;
71
    }
72
}
73