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

FiltersDate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A withPropertyConstraint() 0 22 4
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