Completed
Push — master ( 3723ad...8fd218 )
by WEBEWEB
01:56
created

QueryBuilderFilter::getLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the jquery-querybuilder-bundle package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\QueryBuilderBundle\Model;
13
14
use InvalidArgumentException;
15
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderDecoratorInterface;
16
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderFilterInterface;
17
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderOperatorInterface;
18
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderValidationInterface;
19
use WBW\Bundle\JQuery\QueryBuilderBundle\Serializer\JsonSerializer;
20
21
/**
22
 * QueryBuilder filter.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\Model
26
 */
27
class QueryBuilderFilter extends AbstractQueryBuilder implements QueryBuilderFilterInterface, QueryBuilderOperatorInterface {
28
29
    /**
30
     * Decorator.
31
     *
32
     * @var QueryBuilderDecoratorInterface|null
33
     */
34
    private $decorator;
35
36
    /**
37
     * Label.
38
     *
39
     * @var string
40
     */
41
    private $label;
42
43
    /**
44
     * Multiple.
45
     *
46
     * @var bool
47
     */
48
    private $multiple;
49
50
    /**
51
     * Operators.
52
     *
53
     * @var array
54
     */
55
    private $operators;
56
57
    /**
58
     * Validation.
59
     *
60
     * @var QueryBuilderValidationInterface|null
61
     */
62
    private $validation;
63
64
    /**
65
     * Values.
66
     *
67
     * @var array|null
68
     */
69
    private $values;
70
71
    /**
72
     * Constructor.
73
     *
74
     * @param string $id The id.
75
     * @param string $type The type.
76
     * @param array $operators The operators.
77
     * @throws InvalidArgumentException Throws an invalid argument exception if an argument is invalid.
78
     */
79
    public function __construct(string $id, string $type, array $operators) {
80
        parent::__construct();
81
        $this->setId($id);
82
        $this->setLabel("");
83
        $this->setMultiple(false);
84
        $this->setOperators($operators);
85
        $this->setType($type);
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91
    public function getDecorator(): ?QueryBuilderDecoratorInterface {
92
        return $this->decorator;
93
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98
    public function getLabel(): string {
99
        return $this->label;
100
    }
101
102
    /**
103
     * {@inheritDoc}
104
     */
105
    public function getMultiple(): bool {
106
        return $this->multiple;
107
    }
108
109
    /**
110
     * {@inheritDoc}
111
     */
112
    public function getOperators(): array {
113
        return $this->operators;
114
    }
115
116
    /**
117
     * {@inheritDoc}
118
     */
119
    public function getValidation(): ?QueryBuilderValidationInterface {
120
        return $this->validation;
121
    }
122
123
    /**
124
     * {@inheritDoc}
125
     */
126
    public function getValues(): ?array {
127
        return $this->values;
128
    }
129
130
    /**
131
     * {@inheritDoc}
132
     */
133
    public function jsonSerialize(): array {
134
        return JsonSerializer::serializeQueryBuilderFilter($this);
135
    }
136
137
    /**
138
     * Set the decorator.
139
     *
140
     * @param QueryBuilderDecoratorInterface|null $decorator The decorator.
141
     * @return QueryBuilderFilterInterface Returns this filter.
142
     */
143
    public function setDecorator(?QueryBuilderDecoratorInterface $decorator): QueryBuilderFilterInterface {
144
        $this->decorator = $decorator;
145
        return $this;
146
    }
147
148
    /**
149
     * Set the label.
150
     *
151
     * @param string $label The label.
152
     * @return QueryBuilderFilterInterface Returns this filter.
153
     */
154
    public function setLabel(string $label): QueryBuilderFilterInterface {
155
        $this->label = $label;
156
        return $this;
157
    }
158
159
    /**
160
     * Set the multiple.
161
     *
162
     * @param bool $multiple The multiple.
163
     * @return QueryBuilderFilterInterface Returns this filter.
164
     */
165
    public function setMultiple(bool $multiple): QueryBuilderFilterInterface {
166
        $this->multiple = $multiple;
167
        return $this;
168
    }
169
170
    /**
171
     * Set the operators.
172
     *
173
     * @param array $operators The operators.
174
     * @return QueryBuilderFilterInterface Returns this filter.
175
     * @throws InvalidArgumentException Throws an invalid argument exception if an operator is invalid.
176
     */
177
    public function setOperators(array $operators): QueryBuilderFilterInterface {
178
        $enumOperators = QueryBuilderEnumerator::enumOperators();
179
        foreach ($operators as $current) {
180
            if (null !== $current && false === array_key_exists($current, $enumOperators)) {
181
                throw new InvalidArgumentException(sprintf('The operator "%s" is invalid', $current));
182
            }
183
        }
184
        $this->operators = $operators;
185
        return $this;
186
    }
187
188
    /**
189
     * Set the validation.
190
     *
191
     * @param QueryBuilderValidationInterface|null $validation The validation.
192
     * @return QueryBuilderFilterInterface Returns this filter.
193
     */
194
    public function setValidation(?QueryBuilderValidationInterface $validation): QueryBuilderFilterInterface {
195
        $this->validation = $validation;
196
        return $this;
197
    }
198
199
    /**
200
     * Set the values.
201
     *
202
     * @param array|null $values The values.
203
     * @return QueryBuilderFilterInterface Returns this filter.
204
     */
205
    public function setValues(?array $values): QueryBuilderFilterInterface {
206
        $this->values = $values;
207
        return $this;
208
    }
209
}
210