QueryFilterTrait::withOr()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Bugloos\QueryFilterBundle\Traits;
4
5
use Bugloos\QueryFilterBundle\Enum\ColumnType;
6
use Bugloos\QueryFilterBundle\Enum\StrategyType;
7
8
trait QueryFilterTrait
9
{
10
    public function strategies(array $strategies): self
11
    {
12
        if (empty($strategies)) {
13
            return $this;
14
        }
15
16
        foreach ($strategies as $parameter => $strategy) {
17
            $this->addStrategy($parameter, $strategy);
18
        }
19
20
        return $this;
21
    }
22
23
    public function addStrategy(string $parameter, string $strategy): self
24
    {
25
        if (empty($parameter) || empty($strategy)) {
26
            return $this;
27
        }
28
29
        if (!\in_array($strategy, StrategyType::all(), true)) {
30
            StrategyType::createInvalidArgumentException($strategy);
31
        }
32
33
        $this->strategies[$parameter] = $strategy;
0 ignored issues
show
Bug Best Practice introduced by
The property strategies does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
35
        return $this;
36
    }
37
38
    public function types(array $types): self
39
    {
40
        if (empty($types)) {
41
            return $this;
42
        }
43
44
        foreach ($types as $parameter => $type) {
45
            $this->addType($parameter, $type);
46
        }
47
48
        return $this;
49
    }
50
51
    public function addType(string $parameter, string $type): self
52
    {
53
        if (empty($parameter) || empty($type)) {
54
            return $this;
55
        }
56
57
        if (!\in_array($type, ColumnType::all(), true)) {
58
            StrategyType::createInvalidArgumentException($type);
59
        }
60
61
        $this->types[$parameter] = $type;
0 ignored issues
show
Bug Best Practice introduced by
The property types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
62
63
        return $this;
64
    }
65
66
    public function mappers(array $mappers): self
67
    {
68
        if (empty($mappers)) {
69
            return $this;
70
        }
71
72
        foreach ($mappers as $parameter => $mapper) {
73
            $this->addMapper($parameter, $mapper);
74
        }
75
76
        return $this;
77
    }
78
79
    public function addMapper(string $parameter, string $mapper): self
80
    {
81
        if (empty($parameter) || empty($mapper)) {
82
            return $this;
83
        }
84
85
        $this->mapper[$parameter] = $mapper;
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
86
87
        return $this;
88
    }
89
90
    public function constants(array $constants): self
91
    {
92
        if (empty($constants)) {
93
            return $this;
94
        }
95
96
        foreach ($constants as $parameter => $condition) {
97
            $this->addConstant($parameter, $condition);
98
        }
99
100
        return $this;
101
    }
102
103
    public function addConstant(string $parameter, string $condition): self
104
    {
105
        if (empty($parameter) || empty($condition)) {
106
            return $this;
107
        }
108
109
        $this->constants[$parameter] = $condition;
0 ignored issues
show
Bug Best Practice introduced by
The property constants does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
110
111
        return $this;
112
    }
113
114
    public function cacheTime(int $cacheTime): self
115
    {
116
        $this->cacheTime = $cacheTime;
0 ignored issues
show
Bug Best Practice introduced by
The property cacheTime does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
117
118
        return $this;
119
    }
120
121
    public function withOr(bool $withOr): self
122
    {
123
        $this->withOr = $withOr;
0 ignored issues
show
Bug Best Practice introduced by
The property withOr does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
124
125
        return $this;
126
    }
127
}
128