Completed
Push — master ( b54f87...bde51f )
by Beniamin
04:50
created

JoinComponentTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 68
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
ccs 12
cts 12
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
getTableFactory() 0 1 ?
getQueryBuilder() 0 1 ?
A join() 0 7 1
A crossJoin() 0 4 1
A leftJoin() 0 4 1
A innerJoin() 0 4 1
A getJoinTables() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\SQLBuilder\QueryBuilder\Component;
13
14
use Phuria\SQLBuilder\QueryBuilder\AbstractBuilder;
15
use Phuria\SQLBuilder\Table\AbstractTable;
16
use Phuria\SQLBuilder\TableFactory\TableFactoryInterface;
17
18
/**
19
 * @author Beniamin Jonatan Šimko <[email protected]>
20
 */
21
trait JoinComponentTrait
22
{
23
    /**
24
     * @var array $joinTables
25
     */
26
    private $joinTables = [];
27
28
    /**
29
     * @return TableFactoryInterface
30
     */
31
    abstract protected function getTableFactory();
32
    /**
33
     * @return AbstractBuilder
34
     */
35
    abstract public function getQueryBuilder();
36
37
    /**
38
     * @param string $joinType
39
     * @param mixed  $table
40
     *
41
     * @return AbstractTable
42
     */
43 3
    public function join($joinType, $table)
44
    {
45 3
        $this->joinTables[] = $table = $this->getTableFactory()->createNewTable($table, $this->getQueryBuilder());
46 3
        $table->setJoinType($joinType);
47
48 3
        return $table;
49
    }
50
51
    /**
52
     * @param mixed $table
53
     *
54
     * @return AbstractTable
55
     */
56 1
    public function crossJoin($table)
57
    {
58 1
        return $this->join(AbstractTable::CROSS_JOIN, $table);
59
    }
60
61
    /**
62
     * @param mixed $table
63
     *
64
     * @return AbstractTable
65
     */
66 2
    public function leftJoin($table)
67
    {
68 2
        return $this->join(AbstractTable::LEFT_JOIN, $table);
69
    }
70
71
    /**
72
     * @param string $table
73
     *
74
     * @return AbstractTable
75
     */
76 1
    public function innerJoin($table)
77
    {
78 1
        return $this->join(AbstractTable::INNER_JOIN, $table);
79
    }
80
81
    /**
82
     * @return array
83
     */
84 22
    public function getJoinTables()
85
    {
86 22
        return $this->joinTables;
87
    }
88
}