Completed
Push — master ( efa6a6...b0b60e )
by Beniamin
03:03
created

QueryClauses::getRawJoinClause()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 8.439
cc 5
eloc 13
nc 6
nop 0
crap 5
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\QueryBuilder;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class QueryClauses
18
{
19
    const QUERY_SELECT = 1;
20
    const QUERY_UPDATE = 2;
21
22
    /**
23
     * @var array $selectClauses
24
     */
25
    private $selectClauses = [];
26
27
    /**
28
     * @var array $whereClauses
29
     */
30
    private $whereClauses = [];
31
32
    /**
33
     * @var array $orderByClauses
34
     */
35
    private $orderByClauses = [];
36
37
    /**
38
     * @var array $setClauses
39
     */
40
    private $setClauses = [];
41
42
    /**
43
     * @var array $groupByClauses
44
     */
45
    private $groupByClauses = [];
46
47
    /**
48
     * @var array $havingClauses
49
     */
50
    private $havingClauses = [];
51
52
    /**
53
     * @var string $limitClause
54
     */
55
    private $limitClause;
56
57
    /**
58
     * @return int
59
     */
60 20
    public function guessQueryType()
61
    {
62 20
        if ($this->selectClauses) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->selectClauses of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
63 19
            return static::QUERY_SELECT;
64
        }
65
66 1
        return static::QUERY_UPDATE;
67
    }
68
69
    /**
70
     * @param string $clause
71
     *
72
     * @return $this
73
     */
74 19
    public function addSelect($clause)
75
    {
76 19
        $this->selectClauses[] = $clause;
77
78 19
        return $this;
79
    }
80
81
    /**
82
     * @param string $clause
83
     *
84
     * @return $this
85
     */
86 3
    public function andWhere($clause)
87
    {
88 3
        $this->whereClauses[] = $clause;
89
90 3
        return $this;
91
    }
92
93
    /**
94
     * @param string $clause
95
     *
96
     * @return $this
97
     */
98 1
    public function andHaving($clause)
99
    {
100 1
        $this->havingClauses[] = $clause;
101
102 1
        return $this;
103
    }
104
105
    /**
106
     * @param string $clause
107
     *
108
     * @return $this
109
     */
110 1
    public function addOrderBy($clause)
111
    {
112 1
        $this->orderByClauses[] = $clause;
113
114 1
        return $this;
115
    }
116
117
    /**
118
     * @param string $clause
119
     *
120
     * @return $this
121
     */
122 1
    public function addSet($clause)
123
    {
124 1
        $this->setClauses[] = $clause;
125
126 1
        return $this;
127
    }
128
129
    /**
130
     * @param string $clause
131
     *
132
     * @return $this
133
     */
134 2
    public function addGroupBy($clause)
135
    {
136 2
        $this->groupByClauses[] = $clause;
137
138 2
        return $this;
139
    }
140
141
    /**
142
     * @param string $clause
143
     *
144
     * @return $this
145
     */
146 1
    public function setLimit($clause)
147
    {
148 1
        $this->limitClause = $clause;
149
150 1
        return $this;
151
    }
152
153
    /**
154
     * @return array
155
     */
156 19
    public function getSelectClauses()
157
    {
158 19
        return $this->selectClauses;
159
    }
160
161
    /**
162
     * @return array
163
     */
164 19
    public function getWhereClauses()
165
    {
166 19
        return $this->whereClauses;
167
    }
168
169
    /**
170
     * @return array
171
     */
172 19
    public function getOrderByClauses()
173
    {
174 19
        return $this->orderByClauses;
175
    }
176
177
    /**
178
     * @return array
179
     */
180 1
    public function getSetClauses()
181
    {
182 1
        return $this->setClauses;
183
    }
184
185
    /**
186
     * @return array
187
     */
188 19
    public function getGroupByClauses()
189
    {
190 19
        return $this->groupByClauses;
191
    }
192
193
    /**
194
     * @return array
195
     */
196 19
    public function getHavingClauses()
197
    {
198 19
        return $this->havingClauses;
199
    }
200
201
    /**
202
     * @return string
203
     */
204 19
    public function getLimitClause()
205
    {
206 19
        return $this->limitClause;
207
    }
208
}