Passed
Push — master ( f0e277...a14668 )
by Rougin
03:58
created

Query   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 283
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 26
eloc 34
dl 0
loc 283
rs 10
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 5 1
A sql() 0 3 1
A orderBy() 0 3 1
A insertInto() 0 2 1
A from() 0 5 1
A orWhere() 0 3 1
A innerJoin() 0 5 1
A update() 0 2 1
A __toString() 0 3 1
A types() 0 3 1
A orHaving() 0 3 1
A bindings() 0 3 1
A __construct() 0 3 1
A andOrderBy() 0 3 1
A where() 0 3 1
A instance() 0 3 1
A rightJoin() 0 5 1
A andHaving() 0 3 1
A leftJoin() 0 5 1
A groupBy() 0 5 1
A limit() 0 10 2
A having() 0 3 1
A deleteFrom() 0 2 1
A andWhere() 0 3 1
A builder() 0 5 1
1
<?php
2
3
namespace Rougin\Windstorm\Eloquent;
4
5
use Illuminate\Database\Eloquent\Builder;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Builder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Rougin\Windstorm\QueryInterface;
8
9
class Query implements QueryInterface
10
{
11
    protected $model;
12
13
    /**
14
     * Returns the safe and compiled SQL.
15
     *
16
     * @return string
17
     */
18
    public function __toString()
19
    {
20
        return $this->sql();
21
    }
22
23
    public function __construct(Model $model)
24
    {
25
        $this->model = $model;
26
    }
27
28
    public function builder(Builder $builder)
29
    {
30
        $this->model = $builder;
31
32
        return $this;
33
    }
34
35
    /**
36
     * Generates a SELECT query.
37
     *
38
     * @param  array  $fields
39
     * @return self
40
     */
41
    public function select(array $fields)
42
    {
43
        $this->model = $this->model->select($fields);
44
45
        return $this;
46
    }
47
48
    /**
49
     * Generates a FROM query.
50
     *
51
     * @param  string      $table
52
     * @param  string|null $alias
53
     * @return self
54
     */
55
    public function from($table, $alias = null)
56
    {
57
        $this->model = $this->model->from($table);
58
59
        return $this;
60
    }
61
62
    /**
63
     * Generates an INNER JOIN query.
64
     *
65
     * @param  string $table
66
     * @param  string $local
67
     * @param  string $foreign
68
     * @return self
69
     */
70
    public function innerJoin($table, $local, $foreign)
71
    {
72
        $this->model = $this->model->join($table, $local, '=', $foreign);
73
74
        return $this;
75
    }
76
77
    /**
78
     * Generates a LEFT JOIN query.
79
     *
80
     * @param  string $table
81
     * @param  string $local
82
     * @param  string $foreign
83
     * @return self
84
     */
85
    public function leftJoin($table, $local, $foreign)
86
    {
87
        $this->model = $this->model->join($table, $local, '=', $foreign, 'left');
88
89
        return $this;
90
    }
91
92
    /**
93
     * Generates a RIGHT JOIN query.
94
     *
95
     * @param  string $table
96
     * @param  string $local
97
     * @param  string $foreign
98
     * @return self
99
     */
100
    public function rightJoin($table, $local, $foreign)
101
    {
102
        $this->model = $this->model->join($table, $local, '=', $foreign, 'right');
103
104
        return $this;
105
    }
106
107
    /**
108
     * Generates an INSERT INTO query.
109
     *
110
     * @param  string $table
111
     * @return \Rougin\Windstorm\InsertInterface
112
     */
113
    public function insertInto($table)
114
    {
115
    }
116
117
    /**
118
     * Generates an UPDATE query.
119
     *
120
     * @param  string      $table
121
     * @param  string|null $alias
122
     * @return \Rougin\Windstorm\UpdateInterface
123
     */
124
    public function update($table, $alias = null)
125
    {
126
    }
127
128
    /**
129
     * Generates a DELETE FROM query.
130
     *
131
     * @param  string      $table
132
     * @param  string|null $alias
133
     * @return self
134
     */
135
    public function deleteFrom($table, $alias = null)
136
    {
137
    }
138
139
    /**
140
     * Generates a WHERE query.
141
     *
142
     * @param  string $key
143
     * @return \Rougin\Windstorm\WhereInterface
144
     */
145
    public function where($key)
146
    {
147
        return new Where($this, $this->model, $key, 'and');
148
    }
149
150
    /**
151
     * Generates an AND WHERE query.
152
     *
153
     * @param  string $key
154
     * @return \Rougin\Windstorm\WhereInterface
155
     */
156
    public function andWhere($key)
157
    {
158
        return new Where($this, $this->model, $key, 'and');
159
    }
160
161
    /**
162
     * Generates an OR WHERE query.
163
     *
164
     * @param  string $key
165
     * @return \Rougin\Windstorm\WhereInterface
166
     */
167
    public function orWhere($key)
168
    {
169
        return new Where($this, $this->model, $key, 'or');
170
    }
171
172
    /**
173
     * Generates a GROUP BY query.
174
     *
175
     * @param  array $fields
176
     * @return self
177
     */
178
    public function groupBy(array $fields)
179
    {
180
        $this->model = $this->model->groupBy($fields);
181
182
        return $this;
183
    }
184
185
    /**
186
     * Generates a HAVING query.
187
     *
188
     * @param  string $key
189
     * @return \Rougin\Windstorm\HavingInterface
190
     */
191
    public function having($key)
192
    {
193
        return new Having($this, $this->model, $key);
194
    }
195
196
    /**
197
     * Generates an AND HAVING query.
198
     *
199
     * @param  string $key
200
     * @return \Rougin\Windstorm\HavingInterface
201
     */
202
    public function andHaving($key)
203
    {
204
        return new Having($this, $this->model, $key, 'and');
205
    }
206
207
    /**
208
     * Generates an OR HAVING query.
209
     *
210
     * @param  string $key
211
     * @return \Rougin\Windstorm\HavingInterface
212
     */
213
    public function orHaving($key)
214
    {
215
        return new Having($this, $this->model, $key, 'or');
216
    }
217
218
    /**
219
     * Generates an ORDER BY query.
220
     *
221
     * @param  string $key
222
     * @return \Rougin\Windstorm\OrderInterface
223
     */
224
    public function orderBy($key)
225
    {
226
        return new Order($this, $this->model, $key);
227
    }
228
229
    /**
230
     * Generates a multiple ORDER BY query.
231
     *
232
     * @param  string $key
233
     * @return \Rougin\Windstorm\OrderInterface
234
     */
235
    public function andOrderBy($key)
236
    {
237
        return new Order($this, $this->model, $key);
238
    }
239
240
    /**
241
     * Performs a LIMIT query.
242
     *
243
     * @param  integer      $limit
244
     * @param  integer|null $offset
245
     * @return self
246
     */
247
    public function limit($limit, $offset = null)
248
    {
249
        $this->model = $this->model->limit($limit);
250
251
        if ($offset)
0 ignored issues
show
Bug Best Practice introduced by
The expression $offset of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
252
        {
253
            $this->model = $this->model->offset($offset);
254
        }
255
256
        return $this;
257
    }
258
259
    /**
260
     * Returns the safe and compiled SQL.
261
     *
262
     * @return string
263
     */
264
    public function sql()
265
    {
266
        return $this->model->toSql();
267
    }
268
269
    /**
270
     * Returns the SQL bindings specified.
271
     *
272
     * @return array
273
     */
274
    public function bindings()
275
    {
276
        return $this->model->getBindings();
277
    }
278
279
    /**
280
     * Returns the data types of the bindings.
281
     *
282
     * @return array
283
     */
284
    public function types()
285
    {
286
        return array();
287
    }
288
289
    public function instance()
290
    {
291
        return $this->model;
292
    }
293
}
294