Join::leftJoin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets\Builders;
6
7
use Puzzle\QueryBuilder\Queries\Snippets;
8
9
trait Join
10
{
11
    protected
12
        $joins = array();
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $joins.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
14 5
    public function innerJoin(string $table, ?string $alias = null): self
15
    {
16 5
        $this->joins[] = new Snippets\Joins\InnerJoin($table, $alias);
17
18 5
        return $this;
19
    }
20
21 4
    public function leftJoin(string $table, ?string $alias = null): self
22
    {
23 4
        $this->joins[] = new Snippets\Joins\LeftJoin($table, $alias);
24
25 4
        return $this;
26
    }
27
28 4
    public function rightJoin(string $table, ?string $alias = null): self
29
    {
30 4
        $this->joins[] = new Snippets\Joins\RightJoin($table, $alias);
31
32 4
        return $this;
33
    }
34
35 10
    public function on(string $leftColumn, string $rightColumn): self
36
    {
37 10
        $join = $this->getLastJoin();
38 9
        $join->on($leftColumn, $rightColumn);
39
40 9
        return $this;
41
    }
42
43
    /**
44
     * @param array[string]|string $column
0 ignored issues
show
Documentation introduced by
The doc-type array[string]|string could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
45
     */
46 2
    public function using($column): self
47
    {
48 2
        $join = $this->getLastJoin();
49 2
        $join->using($column);
50
51 2
        return $this;
52
    }
53
54 30
    protected function buildJoin(): string
55
    {
56 30
        $joins = [];
57
58 30
        foreach($this->joins as $innerJoin)
59
        {
60 9
            $joins[] = $innerJoin->toString();
61
        }
62
63 30
        return implode(' ', $joins);
64
    }
65
66 10
    private function getLastJoin(): Snippets\Join
67
    {
68 10
        $lastJoins = end($this->joins);
69
70 10
        if(! $lastJoins instanceof Snippets\Join)
71
        {
72 1
            throw new \LogicException('Erreur dans la récupération de la dernière jointure');
73
        }
74
75 9
        return $lastJoins;
76
    }
77
}
78