Completed
Push — master ( 0073f8...fe0acb )
by wen
12:16
created

Filters::getActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\View\Extensions;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Sco\Admin\Contracts\View\Filters\FilterInterface;
7
8
class Filters extends Extension
9
{
10
    public function add($value)
11
    {
12
        if (!($value instanceof FilterInterface)) {
13
            throw new \InvalidArgumentException(
14
                sprintf(
15
                    'filter must be %s',
16
                    FilterInterface::class
17
                )
18
            );
19
        }
20
    }
21
22
    public function getActive()
23
    {
24
        $this->filter(function (FilterInterface $filter) {
25
            return $filter->isActive();
26
        });
27
    }
28
29
    public function apply(Builder $query)
30
    {
31
        $this->getActive()->each(function (FilterInterface $filter) use ($query) {
0 ignored issues
show
Bug introduced by
The method each cannot be called on $this->getActive() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
32
            $filter->apply($query);
33
        });
34
    }
35
}
36