Passed
Push — master ( 9c833b...4586fd )
by Zing
09:40 queued 04:04
created

BetweenDateTimeFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 15 3
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\Arr;
9
use Illuminate\Support\Carbon;
10
11
class BetweenDateTimeFilter extends BetweenFilter
12
{
13
    /**
14
     * @param mixed $value
15
     * @param string $property
16
     */
17 2
    public function apply(Builder $query, $value, $property): Builder
18
    {
19 2
        $min = Arr::first($value);
20 2
        $max = Arr::last($value);
21 2
        $startAt = Carbon::parse($min);
22 2
        if ($startAt->toDateString() === $min) {
23 1
            $startAt->startOfDay();
24
        }
25
26 2
        $endAt = Carbon::parse($max);
27 2
        if ($endAt->toDateString() === $max) {
28 1
            $endAt->endOfDay();
29
        }
30
31 2
        return parent::apply($query, [$startAt, $endAt], $property);
32
    }
33
}
34