Completed
Push — master ( 1db5f1...1fea5f )
by Beniamin
02:25
created

AbstractTable::isNaturalJoin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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