Passed
Pull Request — master (#148)
by Zing
06:32
created

WithFlaggedFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 29
ccs 16
cts 16
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A enableFlaggedFilter() 0 22 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){
21 1
                $this->formatFilters($filters)->each(
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)->each(
Loading history...
22 1
                    function (Filter $filter) use ($query): void {
23 1
                        $query->orWhere(function ($query) use ($filter) {
24 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

24
                            /** @scrutinizer ignore-call */ 
25
                            $thisIsRequestedFilter = $this->isRequestedFilter($filter);
Loading history...
25 1
                            if ($thisIsRequestedFilter) {
26 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

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