Completed
Push — master ( 8ebb8b...7ca9a5 )
by Beniamin
03:07
created

AbstractTable::addSelect()   A

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 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Phuria\QueryBuilder\Table;
4
5
use Phuria\QueryBuilder\QueryBuilder;
6
use Phuria\QueryBuilder\ReferenceManager;
7
8
/**
9
 * @author Beniamin Jonatan Šimko <[email protected]>
10
 */
11
abstract class AbstractTable
12
{
13
    const CROSS_JOIN = 'CROSS JOIN';
14
    const LEFT_JOIN = 'LEFT JOIN';
15
    const INNER_JOIN = 'INNER JOIN';
16
17
    /**
18
     * @var QueryBuilder $qb
19
     */
20
    private $qb;
21
22
    /**
23
     * @var string $tableAlias
24
     */
25
    private $tableAlias;
26
27
    /**
28
     * @var string $joinType
29
     */
30
    private $joinType;
31
32
    /**
33
     * @var string $joinOn
34
     */
35
    private $joinOn;
36
37
    /**
38
     * @var bool $root
39
     */
40
    private $root = false;
41
42
    /**
43
     * @var bool $join
44
     */
45
    private $join = false;
46
47
    /**
48
     * @param QueryBuilder $qb
49
     */
50 22
    public function __construct(QueryBuilder $qb)
51
    {
52 22
        $this->qb = $qb;
53 22
    }
54
55
    /**
56
     * @return ReferenceManager
57
     */
58 13
    public function __toString()
59
    {
60 13
        return $this->qb->getReferenceManager()->register($this);
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    abstract public function getTableName();
67
68
    /**
69
     * @return QueryBuilder
70
     */
71 1
    public function getQueryBuilder()
72
    {
73 1
        return $this->qb;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 20
    public function getAlias()
80
    {
81 20
        return $this->tableAlias;
82
    }
83
84
    /**
85
     * @param string $alias
86
     *
87
     * @return $this
88
     */
89 8
    public function setAlias($alias)
90
    {
91 8
        $this->tableAlias = $alias;
92
93 8
        return $this;
94
    }
95
96
    /**
97
     * @return bool
98
     */
99 20
    public function isJoin()
100
    {
101 20
        return $this->join;
102
    }
103
104
    /**
105
     * @return string
106
     */
107 3
    public function getJoinType()
108
    {
109 3
        return $this->joinType;
110
    }
111
112
    /**
113
     * @param string $joinType
114
     *
115
     * @return $this
116
     */
117 3
    public function setJoinType($joinType)
118
    {
119 3
        $this->joinType = $joinType;
120 3
        $this->join = true;
121
122 3
        return $this;
123
    }
124
125
    /**
126
     * @return bool
127
     */
128 20
    public function isRoot()
129
    {
130 20
        return $this->root;
131
    }
132
133
    /**
134
     * @param bool $root
135
     *
136
     * @return $this
137
     */
138 22
    public function setRoot($root)
139
    {
140 22
        $this->root = $root;
141
142 22
        return $this;
143
    }
144
145
    /**
146
     * @return string
147
     */
148 13
    public function getAliasOrName()
149
    {
150 13
        return $this->getAlias() ?: $this->getTableName();
151
    }
152
153
    /**
154
     * @param string $clause
155
     *
156
     * @return $this
157
     */
158 5
    public function addSelect($clause)
159
    {
160 5
        $this->qb->addSelect($clause);
161
162 5
        return $this;
163
    }
164
165
    /**
166
     * @param string $clause
167
     *
168
     * @return $this
169
     */
170 2
    public function joinOn($clause)
171
    {
172 2
        $this->joinOn = $clause;
173
174 2
        return $this;
175
    }
176
177
    /**
178
     * @return string
179
     */
180 20
    public function getJoinOn()
181
    {
182 20
        return $this->joinOn;
183
    }
184
185
    /**
186
     * @param string $name
187
     *
188
     * @return string
189
     */
190 13
    public function column($name)
191
    {
192 13
        return $this . '.' . $name;
193
    }
194
}