Passed
Pull Request — master (#51)
by Zing
13:23
created

FiltersDate::withPropertyConstraint()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 22
ccs 12
cts 12
cp 1
crap 4
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Filters;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Support\Facades\DB;
9
10
class FiltersDate extends FiltersExact
11
{
12 1
    protected function withPropertyConstraint(Builder $query, $value, $property): Builder
13
    {
14 1
        if (is_array($value)) {
15 1
            array_map(
16 1
                function ($value) {
17 1
                    if ($value instanceof \DateTimeInterface) {
18 1
                        return $value->format('Y-m-d');
19
                    }
20
21 1
                    return $value;
22 1
                },
23
                $value
24
            );
25
26 1
            return $query->whereIn(DB::raw("date({$property})"), $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->whereIn(I...$property.')'), $value) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
27
        }
28
29 1
        if ($value instanceof \DateTimeInterface) {
30 1
            $value = $value->format('Y-m-d');
31
        }
32
33 1
        return $query->whereDate($property, $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->whereDate($property, $value) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
34
    }
35
}
36