Failed Conditions
Push — 186-self-joins-fail-in-relatio... ( ba3e0e...5bcaaa )
by Bas
08:01 queued 40s
created

BuildsWheres::where()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 77
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 10.0907

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 29
c 1
b 0
f 0
nc 7
nop 4
dl 0
loc 77
ccs 28
cts 31
cp 0.9032
crap 10.0907
rs 7.6666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Query\Concerns;
6
7
use Carbon\CarbonPeriod;
8
use Closure;
9
use DateTimeInterface;
10
use Illuminate\Contracts\Database\Query\ConditionExpression;
11
use Illuminate\Contracts\Support\Arrayable;
12
use Illuminate\Database\Eloquent\Builder as IlluminateEloquentBuilder;
13
use Illuminate\Database\Query\Builder as IlluminateQueryBuilder;
14
use Illuminate\Database\Query\Expression;
15
use Illuminate\Support\Arr;
16
use InvalidArgumentException;
17
use LaravelFreelancerNL\Aranguent\Query\Builder;
18
use LogicException;
19
20
trait BuildsWheres
21
{
22
    /**
23
     * Add a "where fulltext" clause to the query.
24
     *
25
     * @param string|string[] $columns
26
     * @param string $value
27
     * @param array<mixed> $options
28
     * @param string $boolean
29
     * @return $this
30
     *
31
     * @SuppressWarnings("PHPMD.UnusedFormalParameter")
32
     */
33
    public function whereFullText($columns, $value, array $options = [], $boolean = 'and')
34
    {
35
        // NOTE: can be done by listing all fulltext calls and using it on the collection name from $builder->from
36
        // distinctly merging results from multiple calls on the same collection.
37
        // For a call on a joined collection it might need to be moved to the JoinClause
38
        throw new LogicException('This database driver does not support the whereFullText method.');
39
    }
40
41
    /**
42
     * Prepare the value and operator for a where clause.
43
     *
44
     * @param  DateTimeInterface|float|int|string|null  $value
45
     * @param  string|null  $operator
46
     * @param  bool  $useDefault
47
     * @return array<mixed>
48
     *
49
     * @throws \InvalidArgumentException
50
     *
51
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
52 257
     */
53
    public function prepareValueAndOperator($value, $operator, $useDefault = false)
54 257
    {
55 155
        if ($useDefault) {
56 167
            return [$operator, '=='];
57
        } elseif (!is_null($operator) && $this->invalidOperatorAndValue($operator, $value)) {
0 ignored issues
show
Bug introduced by
It seems like invalidOperatorAndValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        } elseif (!is_null($operator) && $this->/** @scrutinizer ignore-call */ invalidOperatorAndValue($operator, $value)) {
Loading history...
58
            throw new InvalidArgumentException('Illegal operator and value combination.');
59
        }
60 167
61
        return [$value, $operator];
62
    }
63
64
    /**
65
     * Add an array of where clauses to the query.
66
     *
67
     * @param  array<mixed>  $column
68
     * @param  string  $boolean
69
     * @param  string  $method
70
     * @return $this
71 29
     */
72
    protected function addArrayOfWheres($column, $boolean, $method = 'where')
73 29
    {
74
        $column = associativeFlatten($column);
75 29
76 29
        return $this->whereNested(function ($query) use ($column, $method, $boolean) {
0 ignored issues
show
Bug introduced by
The method whereNested() does not exist on LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres. Did you maybe mean where()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        return $this->/** @scrutinizer ignore-call */ whereNested(function ($query) use ($column, $method, $boolean) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77 29
            foreach ($column as $key => $value) {
78
                $query->{$method}($key, '==', $value, $boolean);
79 29
            }
80
        }, $boolean);
81
    }
82
83
    /**
84
     * @param mixed $operator
85
     * @param mixed $value
86
     * @return array<mixed>
87 248
     */
88
    public function validateOperator(mixed $operator, mixed $value): array
89
    {
90
        // If the given operator is not found in the list of valid operators we will
91
        // assume that the developer is just short-cutting the '==' operators and
92 248
        // we will set the operators to '==' and set the values appropriately.
93 10
        if ($this->invalidOperator($operator)) {
0 ignored issues
show
Bug introduced by
It seems like invalidOperator() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
        if ($this->/** @scrutinizer ignore-call */ invalidOperator($operator)) {
Loading history...
94
            [$value, $operator] = [$operator, '=='];
95 248
        }
96
        return [$value, $operator];
97
    }
98
99
    /**
100
     * @param mixed $operator
101
     * @return string
102 241
     */
103
    public function getType(mixed $operator): string
104 241
    {
105
        $type = 'Basic';
106 241
107
        if ($this->isBitwiseOperator($operator)) {
0 ignored issues
show
Bug introduced by
It seems like isBitwiseOperator() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        if ($this->/** @scrutinizer ignore-call */ isBitwiseOperator($operator)) {
Loading history...
108
            $type = 'Bitwise';
109
        }
110 241
111
        return $type;
112
    }
113
114
    /**
115
     * Add a date based (year, month, day, time) statement to the query.
116
     *
117
     * @param  string  $type
118
     * @param  string  $column
119
     * @param  string  $operator
120
     * @param  mixed  $value
121
     * @param  string  $boolean
122
     * @return IlluminateQueryBuilder
123 5
     */
124
    protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and')
125 5
    {
126
        $value = $this->bindValue($value);
0 ignored issues
show
Bug introduced by
It seems like bindValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

126
        /** @scrutinizer ignore-call */ 
127
        $value = $this->bindValue($value);
Loading history...
127 5
128
        $this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
129 5
130
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
131
    }
132
133
134
    /**
135
     * Add another query builder as a nested where to the query builder.
136
     *
137
     * @param  \Illuminate\Database\Query\Builder  $query
138
     * @param  string  $boolean
139
     * @return $this
140 52
     */
141
    public function addNestedWhereQuery($query, $boolean = 'and')
142 52
    {
143 52
        if (count($query->wheres)) {
144
            $type = 'Nested';
145 52
146 52
            $this->wheres[] = compact('type', 'query', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
147
            $this->importBindings($query);
0 ignored issues
show
Bug introduced by
It seems like importBindings() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

147
            $this->/** @scrutinizer ignore-call */ 
148
                   importBindings($query);
Loading history...
148
        }
149 52
150
        return $this;
151
    }
152
153
    /**
154
     * Add an exists clause to the query.
155
     *
156
     * @param  \Illuminate\Database\Query\Builder  $query
157
     * @param  string  $boolean
158
     * @param  bool  $not
159
     * @return $this
160
     *
161
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
162 25
     */
163
    public function addWhereExistsQuery(IlluminateQueryBuilder $query, $boolean = 'and', $not = false)
164 25
    {
165
        $type = $not ? 'NotExists' : 'Exists';
166 25
167
        [$subquery] = $this->parseSub($query);
0 ignored issues
show
Bug introduced by
It seems like parseSub() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

167
        /** @scrutinizer ignore-call */ 
168
        [$subquery] = $this->parseSub($query);
Loading history...
168 25
169
        $this->wheres[] = compact('type', 'subquery', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
170 25
171
        return $this;
172
    }
173
174
    /**
175
     * Merge an array of where clauses and bindings.
176
     *
177
     * @param  array<mixed>  $wheres
178
     * @param  array<mixed>  $bindings
179
     * @return $this
180 25
     */
181
    public function mergeWheres($wheres, $bindings)
182 25
    {
183
        $this->wheres = array_merge($this->wheres, (array) $wheres);
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
184 25
185
        $this->bindings['where'] = array_merge($this->bindings['where'], (array) $bindings);
0 ignored issues
show
Bug Best Practice introduced by
The property bindings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
186 25
187
        return $this;
188
    }
189
190
    /**
191
     * Add a basic where clause to the query.
192
     *
193
     * @param  \Closure|IlluminateQueryBuilder|IlluminateEloquentBuilder|Expression|string|array<mixed>  $column
194
     * @param  mixed  $operator
195
     * @param  mixed  $value
196
     * @param  string  $boolean
197
     * @return IlluminateQueryBuilder
198
     *
199
     * @SuppressWarnings("PHPMD.CyclomaticComplexity")
200
     * @SuppressWarnings("PHPMD.NPathComplexity")
201 248
     */
202
    public function where($column, $operator = null, $value = null, $boolean = 'and')
203 248
    {
204
        if ($column instanceof ConditionExpression) {
205
            $type = 'Expression';
206
207
            $this->wheres[] = compact('type', 'column', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
208
209
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
210
        }
211
212
        // If the column is an array, we will assume it is an array of key-value pairs
213
        // and can add them each as a where clause. We will maintain the boolean we
214 248
        // received when the method was called and pass it into the nested where.
215 29
        if (is_array($column) && !array_is_list($column)) {
216
            return $this->addArrayOfWheres($column, $boolean);
217
        }
218
219
        // Here we will make some assumptions about the operator. If only 2 values are
220
        // passed to the method, we will assume that the operator is an equals sign
221 248
        // and keep going. Otherwise, we'll require the operator to be passed in.
222 248
        [$value, $operator] = $this->prepareValueAndOperator(
223 248
            $value,
224 248
            $operator,
225 248
            func_num_args() === 2,
226
        );
227
228
        // If the column is actually a Closure instance, we will assume the developer
229
        // wants to begin a nested where statement which is wrapped in parentheses.
230 248
        // We will add that Closure to the query and return back out immediately.
231 4
        if ($column instanceof Closure && is_null($operator)) {
232
            return $this->whereNested($column, $boolean);
233
        }
234
235
        // If the column is a Closure instance and there is an operator value, we will
236
        // assume the developer wants to run a subquery and then compare the result
237 248
        // of that subquery with the given value that was provided to the method.
238
        if ($this->isQueryable($column) && !is_null($operator)) {
0 ignored issues
show
Bug introduced by
It seems like isQueryable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

238
        if ($this->/** @scrutinizer ignore-call */ isQueryable($column) && !is_null($operator)) {
Loading history...
239 1
            /** @phpstan-ignore-next-line  */
240
            [$subquery] = $this->createSub($column, true);
0 ignored issues
show
Bug introduced by
It seems like createSub() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

240
            /** @scrutinizer ignore-call */ 
241
            [$subquery] = $this->createSub($column, true);
Loading history...
241 1
242
            return $this->where(new Expression($subquery), $operator, $value, $boolean);
243
        }
244 248
245
        list($value, $operator) = $this->validateOperator($operator, $value);
246
247
        // If the value is a Closure, it means the developer is performing an entire
248
        // sub-select within the query and we will need to compile the sub-select
249 248
        // within the where clause to get the appropriate query record results.
250
        if ($this->isQueryable($value)) {
251 1
            /** @phpstan-ignore-next-line  */
252
            return $this->whereSub($column, $operator, $value, $boolean);
253
        }
254
255
        // If the value is "null", we will just assume the developer wants to add a
256
        // where null clause to the query. So, we will allow a short-cut here to
257 248
        // that method for convenience so the developer doesn't have to check.
258
        if (is_null($value)) {
259 16
            /** @phpstan-ignore-next-line  */
260
            return $this->whereNull($column, $boolean, $operator !== '==');
0 ignored issues
show
Bug introduced by
It seems like $column can also be of type Closure and Illuminate\Database\Eloquent\Builder and Illuminate\Database\Query\Builder; however, parameter $columns of LaravelFreelancerNL\Aran...ildsWheres::whereNull() does only seem to accept Illuminate\Contracts\Dat...ray<mixed,mixed>|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

260
            return $this->whereNull(/** @scrutinizer ignore-type */ $column, $boolean, $operator !== '==');
Loading history...
Bug Best Practice introduced by
The expression return $this->whereNull(...an, $operator !== '==') returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
261
        }
262 241
263
        $type = $this->getType($operator);
264 241
265
        $value = $this->bindValue($value);
266
267
        // Now that we are working with just a simple query we can put the elements
268
        // in our array and add the query binding to our array of bindings that
269 241
        // will be bound to each SQL statements when it is finally executed.
270 241
        $this->wheres[] = compact(
271 241
            'type',
272 241
            'column',
273 241
            'operator',
274 241
            'value',
275 241
            'boolean',
276
        );
277 241
278
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
279
    }
280
281
    /**
282
     * Add a where between statement to the query.
283
     *
284
     * @param string|Expression $column
285
     * @param iterable<mixed> $values
286
     * @param string $boolean
287
     * @param bool $not
288
     * @return IlluminateQueryBuilder
289
     *
290
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
291 2
     */
292
    public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
293 2
    {
294
        $type = 'between';
295 2
296
        if ($values instanceof CarbonPeriod) {
297
            $values = $values->toArray();
298
        }
299 2
300 2
        $values = array_slice($this->cleanBindings(Arr::flatten($values)), 0, 2);
0 ignored issues
show
Bug introduced by
It seems like cleanBindings() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

300
        $values = array_slice($this->/** @scrutinizer ignore-call */ cleanBindings(Arr::flatten($values)), 0, 2);
Loading history...
301 2
        $values[0] = $this->bindValue($values[0]);
302
        $values[1] = $this->bindValue($values[1]);
303 2
304
        $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
305 2
306
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
307
    }
308
309
    /**
310
     * Add a "where" clause comparing two columns to the query.
311
     *
312
     * @param  Expression|string|array<mixed>  $first
313
     * @param  string|null  $operator
314
     * @param  Expression|string|null  $second
315
     * @param  string|null  $boolean
316
     * @return $this
317 59
     */
318
    public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
319
    {
320
        // If the column is an array, we will assume it is an array of key-value pairs
321
        // and can add them each as a where clause. We will maintain the boolean we
322 59
        // received when the method was called and pass it into the nested where.
323
        if (is_array($first) && !array_is_list($first) && $boolean !== null) {
324
            return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
325
        }
326
327
        // If the given operator is not found in the list of valid operators we will
328
        // assume that the developer is just short-cutting the '=' operators and
329 59
        // we will set the operators to '=' and set the values appropriately.
330 6
        if ($operator !== null && $this->invalidOperator($operator)) {
331
            [$second, $operator] = [$operator, '='];
332
        }
333
334
        // Finally, we will add this where clause into this array of clauses that we
335
        // are building for the query. All of them will be compiled via a grammar
336 59
        // once the query is about to be executed and run against the database.
337
        $type = 'Column';
338 59
339 59
        $this->wheres[] = compact(
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
340 59
            'type',
341 59
            'first',
342 59
            'operator',
343 59
            'second',
344 59
            'boolean',
345
        );
346 59
347
        return $this;
348
    }
349
350
351
    /**
352
     * Add a "where in" clause to the query.
353
     *
354
     * @param  string  $column
355
     * @param  mixed  $values
356
     * @param  string  $boolean
357
     * @param  bool  $not
358
     * @return IlluminateQueryBuilder
359
     *
360
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
361 20
     */
362
    public function whereIn($column, $values, $boolean = 'and', $not = false)
363 20
    {
364
        $type = $not ? 'NotIn' : 'In';
365
366
        // If the value is a query builder instance we will assume the developer wants to
367
        // look for any values that exist within this given query. So, we will add the
368 20
        // query accordingly so that this query is properly executed when it is run.
369
        if ($this->isQueryable($values)) {
370
            [$query, $bindings] = $this->createSub($values);
371
372
            $values = [new Expression($query)];
373
374
            $this->addBinding($bindings, 'where');
0 ignored issues
show
Bug introduced by
It seems like addBinding() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

374
            $this->/** @scrutinizer ignore-call */ 
375
                   addBinding($bindings, 'where');
Loading history...
375
        }
376
377
        // Next, if the value is Arrayable we need to cast it to its raw array form so we
378
        // have the underlying array value instead of an Arrayable object which is not
379 20
        // able to be added as a binding, etc. We will then add to the wheres array.
380
        if ($values instanceof Arrayable) {
381
            $values = $values->toArray();
382
        }
383 20
384
        $values = $this->bindValue($this->cleanBindings($values));
385 20
386
        $this->wheres[] = compact('type', 'column', 'values', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
387 20
388
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
389
    }
390
391
    /**
392
     * Add a "where JSON contains" clause to the query.
393
     *
394
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
395
     *
396
     * @param  string  $column
397
     * @param  mixed  $value
398
     * @param  string  $boolean
399
     * @param  bool  $not
400
     * @return IlluminateQueryBuilder
401 1
     */
402
    public function whereJsonContains($column, $value, $boolean = 'and', $not = false)
403 1
    {
404
        $type = 'JsonContains';
405 1
406
        $value = $this->bindValue($value);
407 1
408
        $this->wheres[] = compact('type', 'column', 'value', 'boolean', 'not');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
409 1
410
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
411
    }
412
413
    /**
414
     * Add a "where JSON length" clause to the query.
415
     *
416
     * @param  string  $column
417
     * @param  mixed  $operator
418
     * @param  mixed  $value
419
     * @param  string  $boolean
420
     * @return IlluminateQueryBuilder
421 1
     */
422
    public function whereJsonLength($column, $operator, $value = null, $boolean = 'and')
423 1
    {
424
        $type = 'JsonLength';
425 1
426 1
        [$value, $operator] = $this->prepareValueAndOperator(
427 1
            $value,
428 1
            $operator,
429 1
            func_num_args() === 2,
430
        );
431 1
432
        $value = $this->bindValue((int) $this->flattenValue($value));
0 ignored issues
show
Bug introduced by
It seems like flattenValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

432
        $value = $this->bindValue((int) $this->/** @scrutinizer ignore-call */ flattenValue($value));
Loading history...
433 1
434
        $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
435 1
436
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type LaravelFreelancerNL\Aran...y\Concerns\BuildsWheres which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
437
    }
438
439
    /**
440
     * Add a "where like" clause to the query.
441
     *
442
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
443
     * @param  string  $value
444
     * @param  bool  $caseSensitive
445
     * @param  string  $boolean
446
     * @param  bool  $not
447
     * @return $this
448
     *
449
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
450 4
     */
451
    public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false)
452 4
    {
453
        $type = 'Like';
454 4
455
        $value = $this->bindValue($value);
456 4
457
        $this->wheres[] = compact('type', 'column', 'value', 'caseSensitive', 'boolean', 'not');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
458 4
459
        return $this;
460
    }
461
462
    /**
463
     * Add a "where null" clause to the query.
464
     *
465
     * @param  string|array<mixed>|\Illuminate\Contracts\Database\Query\Expression  $columns
466
     * @param  string  $boolean
467
     * @param  bool  $not
468
     * @return $this
469
     *
470
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
471 107
     */
472
    public function whereNull($columns, $boolean = 'and', $not = false)
473 107
    {
474
        $type = $not ? 'NotNull' : 'Null';
475 107
476 107
        foreach (Arr::wrap($columns) as $column) {
477
            $this->wheres[] = compact('type', 'column', 'boolean');
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
478
        }
479 107
480
        return $this;
481
    }
482
483
    /**
484
     * Add a full sub-select to the query.
485
     *
486
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
487
     * @param  string  $operator
488
     * @param  mixed $callback
489
     * @param  string  $boolean
490
     * @return $this
491 1
     */
492
    protected function whereSub($column, $operator, $callback, $boolean)
493
    {
494
        assert($this instanceof Builder);
495 1
496
        $type = 'Sub';
497
498
        // Once we have the query instance we can simply execute it so it can add all
499
        // of the sub-select's conditions to itself, and then we can cache it off
500 1
        // in the array of where clauses for the "main" parent query instance.
501
        call_user_func($callback, $query = $this->forSubQuery());
502
503
        assert($query instanceof Builder);
504 1
505
        $query->returnSingleValue = true;
506 1
507
        [$subquery] = $this->parseSub($query);
508 1
509 1
        $this->wheres[] = compact(
510 1
            'type',
511 1
            'column',
512 1
            'operator',
513 1
            'subquery',
514 1
            'boolean',
515
        );
516 1
517
        return $this;
518
    }
519
520
    /**
521
     * Add a raw where clause to the query.
522
     *
523
     * @param  string  $sql
524
     * @param  mixed  $bindings
525
     * @param  string  $boolean
526
     * @return $this
527
     */
528
    public function whereRaw($sql, $bindings = [], $boolean = 'and')
529
    {
530
        $this->wheres[] = ['type' => 'raw', 'sql' => $sql, 'boolean' => $boolean];
0 ignored issues
show
Bug Best Practice introduced by
The property wheres does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
531
532
        $this->bindings['where'] = array_merge($this->bindings['where'], (array) $bindings);
0 ignored issues
show
Bug Best Practice introduced by
The property bindings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
533
534
        return $this;
535
    }
536
}
537