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

BetweenDateTimeFilter::apply()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 3
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
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