Completed
Push — master ( 465cad...ece51a )
by Beniamin
02:47
created

AbstractTable::column()   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
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Phuria\SQLBuilder\Table;
4
5
use Phuria\SQLBuilder\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
     * @return BuilderInterface
68
     */
69 2
    public function getQueryBuilder()
70
    {
71 2
        return $this->qb;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 1
    public function getAlias()
78
    {
79 1
        return $this->tableAlias;
80
    }
81
82
    /**
83
     * @param string $alias
84
     *
85
     * @return $this
86
     */
87 1
    public function setAlias($alias)
88
    {
89 1
        $this->tableAlias = $alias;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97 2
    public function isJoin()
98
    {
99 2
        return (bool) $this->joinType;
100
    }
101
102
    /**
103
     * @return int
104
     */
105 1
    public function getJoinType()
106
    {
107 1
        return $this->joinType;
108
    }
109
110
    /**
111
     * @param int $joinType
112
     */
113 1
    public function setJoinType($joinType)
114
    {
115 1
        $this->joinType = $joinType;
116 1
    }
117
118
    /**
119
     * @param string $clause
120
     */
121 1
    public function joinOn($clause)
122
    {
123 1
        $this->joinOn = $clause;
124 1
    }
125
126
    /**
127
     * @return string
128
     */
129 1
    public function getJoinOn()
130
    {
131 1
        return $this->joinOn;
132
    }
133
134
    /**
135
     * @return boolean
136
     */
137 1
    public function isOuterJoin()
138
    {
139 1
        return $this->outerJoin;
140
    }
141
142
    /**
143
     * @param boolean $outerJoin
144
     */
145 1
    public function setOuterJoin($outerJoin)
146
    {
147 1
        $this->outerJoin = $outerJoin;
148 1
    }
149
150
    /**
151
     * @return boolean
152
     */
153 1
    public function isNaturalJoin()
154
    {
155 1
        return $this->naturalJoin;
156
    }
157
158
    /**
159
     * @param boolean $naturalJoin
160
     */
161 1
    public function setNaturalJoin($naturalJoin)
162
    {
163 1
        $this->naturalJoin = $naturalJoin;
164 1
    }
165
166
    /**
167
     * @param string $name
168
     *
169
     * @return string
170
     */
171 1
    public function column($name)
172
    {
173 1
        return $this . '.' . $name;
174
    }
175
}