Completed
Push — master ( 3e85c1...f2d587 )
by Beniamin
09:13
created

AbstractTable::setHint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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 $alias;
21
22
    /**
23
     * @var null|JoinMetadata
24
     */
25
    private $joinMetadata;
26
27
    /**
28
     * @var array $hints
29
     */
30 4
    private $hints = [];
31
32 4
    /**
33 4
     * @param BuilderInterface $qb
34
     */
35
    public function __construct(BuilderInterface $qb)
36
    {
37
        $this->qb = $qb;
38 2
    }
39
    /**
40 2
     * @return string
41
     */
42
    public function __toString()
43
    {
44
        return $this->getQueryBuilder()->toReference($this);
45
    }
46 1
47
    /**
48 1
     * @inheritdoc
49
     */
50
    public function getAliasOrName()
51
    {
52
        return $this->getAlias() ?: $this->getTableName();
53
    }
54 1
55
    /**
56 1
     * @return bool
57
     */
58
    public function isJoin()
59
    {
60
        return null !== $this->joinMetadata;
61
    }
62 2
63
    /**
64 2
     * @return BuilderInterface
65
     */
66
    public function getQueryBuilder()
67
    {
68
        return $this->qb;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function relative(callable $callback = null)
75
    {
76
        $callback($this->getRelativeBuilder());
77
78
        return $this;
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function getRelativeBuilder()
85
    {
86
        return new RelativeQueryBuilder($this->getQueryBuilder(), $this);
87
    }
88 1
89
    /**
90 1
     * @return string
91
     */
92
    public function getAlias()
93
    {
94
        return $this->alias;
95
    }
96
97
    /**
98 1
     * @param string $alias
99
     *
100 1
     * @return $this
101
     */
102 1
    public function setAlias($alias)
103
    {
104
        $this->alias = $alias;
105
106
        return $this;
107
    }
108
109
    /**
110 1
     * @param string $name
111
     *
112 1
     * @return string
113
     */
114
    public function column($name)
115
    {
116
        return $this . '.' . $name;
117
    }
118
119
    /**
120
     * @inheritdoc
121
     */
122
    public function getJoinMetadata()
123
    {
124
        return $this->joinMetadata;
125
    }
126
127
    /**
128
     * @param JoinMetadata $joinMetadata
129
     *
130
     * @return AbstractTable
131
     */
132
    public function setJoinMetadata(JoinMetadata $joinMetadata)
133
    {
134
        $this->joinMetadata = $joinMetadata;
135
136
        return $this;
137
    }
138
139
    /**
140
     * @param mixed $hint
141
     *
142
     * @return mixed
143
     */
144
    public function getHint($hint)
145
    {
146
        return $this->hints[$hint];
147
    }
148
149
    /**
150
     * @param mixed $hint
151
     *
152
     * @return bool
153
     */
154
    public function hasHint($hint)
155
    {
156
        return array_key_exists($hint, $this->hints);
157
    }
158
159
    /**
160
     * @param mixed $hint
161
     * @param mixed $value
162
     *
163
     * @return $this
164
     */
165
    public function setHint($hint, $value = true)
166
    {
167
        $this->hints[$hint] = $value;
168
169
        return $this;
170
    }
171
172
}