Passed
Pull Request — master (#28)
by Zing
05:34
created

FiltersBetweenDateTime   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 25
ccs 12
cts 14
cp 0.8571
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 23 5
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\Carbon;
9
10
class FiltersBetweenDateTime extends FiltersBetween
11
{
12 1
    public function apply(Builder $query, $value, $property): Builder
13
    {
14 1
        $min = head($value);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $min is correct as head($value) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The call to head() has too many arguments starting with $value. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        $min = /** @scrutinizer ignore-call */ head($value);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
15 1
        $max = last($value);
16 1
        if (is_string($min)) {
0 ignored issues
show
introduced by
The condition is_string($min) is always false.
Loading history...
17 1
            $startAt = Carbon::parse($min);
18 1
            if ($startAt->toDateString() === $min) {
19 1
                $startAt->startOfDay();
20
            }
21
        } else {
22
            $startAt = $min;
23
        }
24
25 1
        if (is_string($max)) {
26 1
            $endAt = Carbon::parse($max);
27 1
            if ($endAt->toDateString() === $max) {
28 1
                $endAt->endOfDay();
29
            }
30
        } else {
31
            $endAt = $max;
32
        }
33
34 1
        return parent::apply($query, [$startAt, $endAt], $property);
35
    }
36
}
37