Completed
Push — master ( 94029f...e94e78 )
by Beniamin
02:32
created

AbstractTable::getJoinMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * @param BuilderInterface $qb
29
     */
30 4
    public function __construct(BuilderInterface $qb)
31
    {
32 4
        $this->qb = $qb;
33 4
    }
34
35
    /**
36
     * @return string
37
     */
38 2
    public function __toString()
39
    {
40 2
        return $this->getQueryBuilder()->toReference($this);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 1
    public function getAliasOrName()
47
    {
48 1
        return $this->getAlias() ?: $this->getTableName();
49
    }
50
51
    /**
52
     * @return bool
53
     */
54 1
    public function isJoin()
55
    {
56 1
        return null !== $this->joinMetadata;
57
    }
58
59
    /**
60
     * @return BuilderInterface
61
     */
62 2
    public function getQueryBuilder()
63
    {
64 2
        return $this->qb;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function relative(callable $callback = null)
71
    {
72
        $callback($this->getRelativeBuilder());
73
74
        return $this;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function getRelativeBuilder()
81
    {
82
        return new RelativeQueryBuilder($this->getQueryBuilder(), $this);
83
    }
84
85
    /**
86
     * @return string
87
     */
88 1
    public function getAlias()
89
    {
90 1
        return $this->alias;
91
    }
92
93
    /**
94
     * @param string $alias
95
     *
96
     * @return $this
97
     */
98 1
    public function setAlias($alias)
99
    {
100 1
        $this->alias = $alias;
101
102 1
        return $this;
103
    }
104
105
    /**
106
     * @param string $name
107
     *
108
     * @return string
109
     */
110 1
    public function column($name)
111
    {
112 1
        return $this . '.' . $name;
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118
    public function getJoinMetadata()
119
    {
120
        return $this->joinMetadata;
121
    }
122
123
    /**
124
     * @param JoinMetadata $joinMetadata
125
     *
126
     * @return AbstractTable
127
     */
128
    public function setJoinMetadata(JoinMetadata $joinMetadata)
129
    {
130
        $this->joinMetadata = $joinMetadata;
131
132
        return $this;
133
    }
134
}