Completed
Pull Request — master (#59)
by
unknown
01:56
created

Filter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A filter() 0 6 1
A exact() 0 4 1
A partial() 0 4 1
A scope() 0 4 1
A custom() 0 4 1
A getProperty() 0 4 1
A isForProperty() 0 4 1
1
<?php
2
3
namespace Spatie\QueryBuilder;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Spatie\QueryBuilder\Filters\FiltersExact;
7
use Spatie\QueryBuilder\Filters\FiltersPartial;
8
use Spatie\QueryBuilder\Filters\FiltersScope;
9
10
class Filter
11
{
12
    /** @var string */
13
    protected $filterClass;
14
15
    /** @var string */
16
    protected $property;
17
18
    public function __construct(string $property, string $filterClass)
19
    {
20
        $this->property = $property;
21
        $this->filterClass = $filterClass;
22
    }
23
24
    public function filter(Builder $builder, $value)
25
    {
26
        $filterClass = new $this->filterClass;
27
28
        ($filterClass)($builder, $value, $this->property);
29
    }
30
31
    public static function exact(string $property) : self
32
    {
33
        return new static($property, FiltersExact::class);
34
    }
35
36
    public static function partial(string $property) : self
37
    {
38
        return new static($property, FiltersPartial::class);
39
    }
40
41
    public static function scope(string $property) : self
42
    {
43
        return new static($property, FiltersScope::class);
44
    }
45
46
    public static function custom(string $property, string $filterClass) : self
47
    {
48
        return new static($property, $filterClass);
49
    }
50
51
    public function getProperty(): string
52
    {
53
        return $this->property;
54
    }
55
56
    public function isForProperty(string $property): bool
57
    {
58
        return $this->property === $property;
59
    }
60
}
61