Passed
Push — master ( 357300...ec9982 )
by Zing
13:33 queued 07:41
created

WithFlaggedFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 32
ccs 17
cts 17
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A enableFlaggedFilter() 0 25 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Concerns;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Zing\QueryBuilder\Filter;
9
10
trait WithFlaggedFilter
11
{
12
    /**
13
     * @param array<string|\Zing\QueryBuilder\Filter> $filters
14
     *
15
     * @return $this
16
     */
17 1
    public function enableFlaggedFilter(array $filters): self
18
    {
19 1
        $this->where(
0 ignored issues
show
Bug introduced by
It seems like where() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

19
        $this->/** @scrutinizer ignore-call */ 
20
               where(
Loading history...
20 1
            function (Builder $query) use ($filters): void {
21 1
                $this->formatFilters($filters)
0 ignored issues
show
Bug introduced by
It seems like formatFilters() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
                $this->/** @scrutinizer ignore-call */ 
22
                       formatFilters($filters)
Loading history...
22 1
                    ->each(
23 1
                        function (Filter $filter) use ($query): void {
24 1
                            $query->orWhere(function ($query) use ($filter): void {
25 1
                                $thisIsRequestedFilter = $this->isRequestedFilter($filter);
0 ignored issues
show
Bug introduced by
It seems like isRequestedFilter() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

25
                                /** @scrutinizer ignore-call */ 
26
                                $thisIsRequestedFilter = $this->isRequestedFilter($filter);
Loading history...
26 1
                                if ($thisIsRequestedFilter) {
27 1
                                    $filter->filter($query, $this->getFilterValue($filter));
0 ignored issues
show
Bug introduced by
It seems like getFilterValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
                                    $filter->filter($query, $this->/** @scrutinizer ignore-call */ getFilterValue($filter));
Loading history...
28
29 1
                                    return;
30
                                }
31
32 1
                                if ($filter->hasDefault()) {
33 1
                                    $filter->filter($query, $filter->getDefault());
34
                                }
35 1
                            });
36 1
                        }
37
                    );
38 1
            }
39
        );
40
41 1
        return $this;
42
    }
43
}
44