Join   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 66
wmc 20
lcom 1
cbo 3
ccs 30
cts 30
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A innerJoin() 0 6 1
A leftJoin() 0 6 1
A rightJoin() 0 6 1
A on() 0 7 1
A using() 0 7 1
A buildJoin() 0 11 2
A getLastJoin() 0 11 2
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