Passed
Push — 167-support-wherelike-orwherel... ( ca86a6...2b1378 )
by Bas
03:36
created

BuildsWheres::whereLike()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 10
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 Illuminate\Contracts\Database\Query\ConditionExpression;
10
use Illuminate\Contracts\Support\Arrayable;
11
use Illuminate\Database\Eloquent\Builder as IlluminateEloquentBuilder;
12
use Illuminate\Database\Query\Builder as IlluminateQueryBuilder;
13
use Illuminate\Database\Query\Expression;
14
use Illuminate\Support\Arr;
15
use InvalidArgumentException;
16
use LaravelFreelancerNL\Aranguent\Query\Builder;
17
use LogicException;
18
19
trait BuildsWheres
20
{
21
    /**
22
     * Add a "where fulltext" clause to the query.
23
     *
24
     * @param string|string[] $columns
25
     * @param string $value
26
     * @param array<mixed> $options
27
     * @param string $boolean
28
     * @return $this
29
     *
30
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
31
     */
32
    public function whereFullText($columns, $value, array $options = [], $boolean = 'and')
33
    {
34
        // NOTE: can be done by listing all fulltext calls and using it on the collection name from $builder->from
35
        // distinctly merging results from multiple calls on the same collection.
36
        // For a call on a joined collection it might need to be moved to the JoinClause
37
        throw new LogicException('This database driver does not support the whereFullText method.');
38
    }
39
40
    /**
41
     * Prepare the value and operator for a where clause.
42
     *
43
     * @param  float|int|string|null  $value
44
     * @param  string|null  $operator
45
     * @param  bool  $useDefault
46
     * @return array<mixed>
47
     *
48
     * @throws \InvalidArgumentException
49
     *
50
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
51
     */
52 229
    public function prepareValueAndOperator($value, $operator, $useDefault = false)
53
    {
54 229
        if ($useDefault) {
55 138
            return [$operator, '=='];
56 147
        } 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

56
        } elseif (!is_null($operator) && $this->/** @scrutinizer ignore-call */ invalidOperatorAndValue($operator, $value)) {
Loading history...
57
            throw new InvalidArgumentException('Illegal operator and value combination.');
58
        }
59
60 147
        return [$value, $operator];
61
    }
62
63
    /**
64
     * Add an array of where clauses to the query.
65
     *
66
     * @param  array<mixed>  $column
67
     * @param  string  $boolean
68
     * @param  string  $method
69
     * @return $this
70
     */
71 29
    protected function addArrayOfWheres($column, $boolean, $method = 'where')
72
    {
73 29
        $column = associativeFlatten($column);
74
75 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

75
        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...
76 29
            foreach ($column as $key => $value) {
77 29
                $query->{$method}($key, '==', $value, $boolean);
78
            }
79 29
        }, $boolean);
80
    }
81
82
    /**
83
     * @param mixed $operator
84
     * @param mixed $value
85
     * @return array<mixed>
86
     */
87 220
    public function validateOperator(mixed $operator, mixed $value): array
88
    {
89
        // If the given operator is not found in the list of valid operators we will
90
        // assume that the developer is just short-cutting the '==' operators and
91
        // we will set the operators to '==' and set the values appropriately.
92 220
        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

92
        if ($this->/** @scrutinizer ignore-call */ invalidOperator($operator)) {
Loading history...
93 4
            [$value, $operator] = [$operator, '=='];
94
        }
95 220
        return [$value, $operator];
96
    }
97
98
    /**
99
     * @param mixed $operator
100
     * @return string
101
     */
102 213
    public function getType(mixed $operator): string
103
    {
104 213
        $type = 'Basic';
105
106 213
        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

106
        if ($this->/** @scrutinizer ignore-call */ isBitwiseOperator($operator)) {
Loading history...
107
            $type = 'Bitwise';
108
        }
109
110 213
        return $type;
111
    }
112
113
    /**
114
     * Add a date based (year, month, day, time) statement to the query.
115
     *
116
     * @param  string  $type
117
     * @param  string  $column
118
     * @param  string  $operator
119
     * @param  mixed  $value
120
     * @param  string  $boolean
121
     * @return IlluminateQueryBuilder
122
     */
123 5
    protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and')
124
    {
125 5
        $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

125
        /** @scrutinizer ignore-call */ 
126
        $value = $this->bindValue($value);
Loading history...
126
127 5
        $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...
128
129 5
        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...
130
    }
131
132
133
    /**
134
     * Add another query builder as a nested where to the query builder.
135
     *
136
     * @param  \Illuminate\Database\Query\Builder  $query
137
     * @param  string  $boolean
138
     * @return $this
139
     */
140 39
    public function addNestedWhereQuery($query, $boolean = 'and')
141
    {
142 39
        if (count($query->wheres)) {
143 39
            $type = 'Nested';
144
145 39
            $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...
146 39
            $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

146
            $this->/** @scrutinizer ignore-call */ 
147
                   importBindings($query);
Loading history...
147
        }
148
149 39
        return $this;
150
    }
151
152
    /**
153
     * Add an exists clause to the query.
154
     *
155
     * @param  \Illuminate\Database\Query\Builder  $query
156
     * @param  string  $boolean
157
     * @param  bool  $not
158
     * @return $this
159
     *
160
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
161
     */
162 7
    public function addWhereExistsQuery(IlluminateQueryBuilder $query, $boolean = 'and', $not = false)
163
    {
164 7
        $type = $not ? 'NotExists' : 'Exists';
165
166 7
        [$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

166
        /** @scrutinizer ignore-call */ 
167
        [$subquery] = $this->parseSub($query);
Loading history...
167
168 7
        $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...
169
170 7
        return $this;
171
    }
172
173
    /**
174
     * Merge an array of where clauses and bindings.
175
     *
176
     * @param  array<mixed>  $wheres
177
     * @param  array<mixed>  $bindings
178
     * @return $this
179
     */
180 7
    public function mergeWheres($wheres, $bindings)
181
    {
182 7
        $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...
183
184 7
        $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...
185
186 7
        return $this;
187
    }
188
189
    /**
190
     * Add a basic where clause to the query.
191
     *
192
     * @param  \Closure|IlluminateQueryBuilder|IlluminateEloquentBuilder|Expression|string|array<mixed>  $column
193
     * @param  mixed  $operator
194
     * @param  mixed  $value
195
     * @param  string  $boolean
196
     * @return IlluminateQueryBuilder
197
     *
198
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
199
     * @SuppressWarnings(PHPMD.NPathComplexity)
200
     */
201 220
    public function where($column, $operator = null, $value = null, $boolean = 'and')
202
    {
203 220
        if ($column instanceof ConditionExpression) {
204
            $type = 'Expression';
205
206
            $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...
207
208
            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...
209
        }
210
211
        // If the column is an array, we will assume it is an array of key-value pairs
212
        // and can add them each as a where clause. We will maintain the boolean we
213
        // received when the method was called and pass it into the nested where.
214 220
        if (is_array($column) && !array_is_list($column)) {
215 29
            return $this->addArrayOfWheres($column, $boolean);
216
        }
217
218
        // Here we will make some assumptions about the operator. If only 2 values are
219
        // passed to the method, we will assume that the operator is an equals sign
220
        // and keep going. Otherwise, we'll require the operator to be passed in.
221 220
        [$value, $operator] = $this->prepareValueAndOperator(
222 220
            $value,
223 220
            $operator,
224 220
            func_num_args() === 2,
225 220
        );
226
227
        // If the column is actually a Closure instance, we will assume the developer
228
        // wants to begin a nested where statement which is wrapped in parentheses.
229
        // We will add that Closure to the query and return back out immediately.
230 220
        if ($column instanceof Closure && is_null($operator)) {
231 4
            return $this->whereNested($column, $boolean);
232
        }
233
234
        // If the column is a Closure instance and there is an operator value, we will
235
        // assume the developer wants to run a subquery and then compare the result
236
        // of that subquery with the given value that was provided to the method.
237 220
        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

237
        if ($this->/** @scrutinizer ignore-call */ isQueryable($column) && !is_null($operator)) {
Loading history...
238
            /** @phpstan-ignore-next-line  */
239 1
            [$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

239
            /** @scrutinizer ignore-call */ 
240
            [$subquery] = $this->createSub($column, true);
Loading history...
240
241 1
            return $this->where(new Expression($subquery), $operator, $value, $boolean);
242
        }
243
244 220
        list($value, $operator) = $this->validateOperator($operator, $value);
245
246
        // If the value is a Closure, it means the developer is performing an entire
247
        // sub-select within the query and we will need to compile the sub-select
248
        // within the where clause to get the appropriate query record results.
249 220
        if ($this->isQueryable($value)) {
250
            /** @phpstan-ignore-next-line  */
251 1
            return $this->whereSub($column, $operator, $value, $boolean);
252
        }
253
254
        // If the value is "null", we will just assume the developer wants to add a
255
        // where null clause to the query. So, we will allow a short-cut here to
256
        // that method for convenience so the developer doesn't have to check.
257 220
        if (is_null($value)) {
258
            /** @phpstan-ignore-next-line  */
259 12
            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

259
            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...
260
        }
261
262 213
        $type = $this->getType($operator);
263
264 213
        $value = $this->bindValue($value);
265
266
        // Now that we are working with just a simple query we can put the elements
267
        // in our array and add the query binding to our array of bindings that
268
        // will be bound to each SQL statements when it is finally executed.
269 213
        $this->wheres[] = compact(
270 213
            'type',
271 213
            'column',
272 213
            'operator',
273 213
            'value',
274 213
            'boolean',
275 213
        );
276
277 213
        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...
278
    }
279
280
    /**
281
     * Add a where between statement to the query.
282
     *
283
     * @param string|Expression $column
284
     * @param iterable<mixed> $values
285
     * @param string $boolean
286
     * @param bool $not
287
     * @return IlluminateQueryBuilder
288
     *
289
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
290
     */
291 2
    public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
292
    {
293 2
        $type = 'between';
294
295 2
        if ($values instanceof CarbonPeriod) {
296
            $values = $values->toArray();
297
        }
298
299 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

299
        $values = array_slice($this->/** @scrutinizer ignore-call */ cleanBindings(Arr::flatten($values)), 0, 2);
Loading history...
300 2
        $values[0] = $this->bindValue($values[0]);
301 2
        $values[1] = $this->bindValue($values[1]);
302
303 2
        $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...
304
305 2
        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...
306
    }
307
308
    /**
309
     * Add a "where" clause comparing two columns to the query.
310
     *
311
     * @param  Expression|string|array<mixed>  $first
312
     * @param  string|null  $operator
313
     * @param  Expression|string|null  $second
314
     * @param  string|null  $boolean
315
     * @return $this
316
     */
317 36
    public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
318
    {
319
        // If the column is an array, we will assume it is an array of key-value pairs
320
        // and can add them each as a where clause. We will maintain the boolean we
321
        // received when the method was called and pass it into the nested where.
322 36
        if (is_array($first) && !array_is_list($first) && $boolean !== null) {
323
            return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
324
        }
325
326
        // If the given operator is not found in the list of valid operators we will
327
        // assume that the developer is just short-cutting the '=' operators and
328
        // we will set the operators to '=' and set the values appropriately.
329 36
        if ($operator !== null && $this->invalidOperator($operator)) {
330 6
            [$second, $operator] = [$operator, '='];
331
        }
332
333
        // Finally, we will add this where clause into this array of clauses that we
334
        // are building for the query. All of them will be compiled via a grammar
335
        // once the query is about to be executed and run against the database.
336 36
        $type = 'Column';
337
338 36
        $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...
339 36
            'type',
340 36
            'first',
341 36
            'operator',
342 36
            'second',
343 36
            'boolean',
344 36
        );
345
346 36
        return $this;
347
    }
348
349
350
    /**
351
     * Add a "where in" clause to the query.
352
     *
353
     * @param  string  $column
354
     * @param  mixed  $values
355
     * @param  string  $boolean
356
     * @param  bool  $not
357
     * @return IlluminateQueryBuilder
358
     *
359
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
360
     */
361 20
    public function whereIn($column, $values, $boolean = 'and', $not = false)
362
    {
363 20
        $type = $not ? 'NotIn' : 'In';
364
365
        // If the value is a query builder instance we will assume the developer wants to
366
        // look for any values that exist within this given query. So, we will add the
367
        // query accordingly so that this query is properly executed when it is run.
368 20
        if ($this->isQueryable($values)) {
369
            [$query, $bindings] = $this->createSub($values);
370
371
            $values = [new Expression($query)];
372
373
            $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

373
            $this->/** @scrutinizer ignore-call */ 
374
                   addBinding($bindings, 'where');
Loading history...
374
        }
375
376
        // Next, if the value is Arrayable we need to cast it to its raw array form so we
377
        // have the underlying array value instead of an Arrayable object which is not
378
        // able to be added as a binding, etc. We will then add to the wheres array.
379 20
        if ($values instanceof Arrayable) {
380
            $values = $values->toArray();
381
        }
382
383 20
        $values = $this->bindValue($this->cleanBindings($values));
384
385 20
        $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...
386
387 20
        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...
388
    }
389
390
    /**
391
     * Add a "where JSON contains" clause to the query.
392
     *
393
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
394
     *
395
     * @param  string  $column
396
     * @param  mixed  $value
397
     * @param  string  $boolean
398
     * @param  bool  $not
399
     * @return IlluminateQueryBuilder
400
     */
401 1
    public function whereJsonContains($column, $value, $boolean = 'and', $not = false)
402
    {
403 1
        $type = 'JsonContains';
404
405 1
        $value = $this->bindValue($value);
406
407 1
        $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...
408
409 1
        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...
410
    }
411
412
    /**
413
     * Add a "where JSON length" clause to the query.
414
     *
415
     * @param  string  $column
416
     * @param  mixed  $operator
417
     * @param  mixed  $value
418
     * @param  string  $boolean
419
     * @return IlluminateQueryBuilder
420
     */
421 1
    public function whereJsonLength($column, $operator, $value = null, $boolean = 'and')
422
    {
423 1
        $type = 'JsonLength';
424
425 1
        [$value, $operator] = $this->prepareValueAndOperator(
426 1
            $value,
427 1
            $operator,
428 1
            func_num_args() === 2,
429 1
        );
430
431 1
        $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

431
        $value = $this->bindValue((int) $this->/** @scrutinizer ignore-call */ flattenValue($value));
Loading history...
432
433 1
        $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...
434
435 1
        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...
436
    }
437
438
    /**
439
     * Add a "where like" clause to the query.
440
     *
441
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
442
     * @param  string  $value
443
     * @param  bool  $caseSensitive
444
     * @param  string  $boolean
445
     * @param  bool  $not
446
     * @return $this
447
     */
448 4
    public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false)
449
    {
450 4
        $type = 'Like';
451
452 4
        $value = $this->bindValue($value);
453
454 4
        $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...
455
456 4
        return $this;
457
    }
458
459
    /**
460
     * Add a "where null" clause to the query.
461
     *
462
     * @param  string|array<mixed>|\Illuminate\Contracts\Database\Query\Expression  $columns
463
     * @param  string  $boolean
464
     * @param  bool  $not
465
     * @return $this
466
     *
467
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
468
     */
469 90
    public function whereNull($columns, $boolean = 'and', $not = false)
470
    {
471 90
        $type = $not ? 'NotNull' : 'Null';
472
473 90
        foreach (Arr::wrap($columns) as $column) {
474 90
            $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...
475
        }
476
477 90
        return $this;
478
    }
479
480
    /**
481
     * Add a full sub-select to the query.
482
     *
483
     * @param  \Illuminate\Contracts\Database\Query\Expression|string  $column
484
     * @param  string  $operator
485
     * @param  mixed $callback
486
     * @param  string  $boolean
487
     * @return $this
488
     */
489 1
    protected function whereSub($column, $operator, $callback, $boolean)
490
    {
491
        assert($this instanceof Builder);
492
493 1
        $type = 'Sub';
494
495
        // Once we have the query instance we can simply execute it so it can add all
496
        // of the sub-select's conditions to itself, and then we can cache it off
497
        // in the array of where clauses for the "main" parent query instance.
498 1
        call_user_func($callback, $query = $this->forSubQuery());
499
500
        assert($query instanceof Builder);
501
502 1
        $query->returnSingleValue = true;
503
504 1
        [$subquery] = $this->parseSub($query);
505
506 1
        $this->wheres[] = compact(
507 1
            'type',
508 1
            'column',
509 1
            'operator',
510 1
            'subquery',
511 1
            'boolean',
512 1
        );
513
514 1
        return $this;
515
    }
516
}
517