Completed
Push — master ( c5595c...1ceb82 )
by WEBEWEB
01:24
created

QueryBuilderRuleSet::setFilterSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the jquery-querybuilder-bundle package.
5
 *
6
 * (c) 2019 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\API;
13
14
use InvalidArgumentException;
15
16
/**
17
 * QueryBuilder rule set.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\API
21
 */
22
class QueryBuilderRuleSet implements QueryBuilderConditionInterface, QueryBuilderRuleSetInterface {
23
24
    /**
25
     * Condition.
26
     *
27
     * @var string
28
     */
29
    private $condition;
30
31
    /**
32
     * Rules.
33
     *
34
     * @var array
35
     */
36
    private $rules;
37
38
    /**
39
     * Valid.
40
     *
41
     * @var bool
42
     */
43
    private $valid;
44
45
    /**
46
     * Constructor.
47
     */
48
    public function __construct() {
49
        $this->setRules([]);
50
        $this->setValid(false);
51
    }
52
53
    /**
54
     * Add a rule.
55
     *
56
     * @param QueryBuilderRuleInterface $rule The rule.
57
     * @return QueryBuilderRuleSetInterface Returns this rule set.
58
     */
59
    public function addRule(QueryBuilderRuleInterface $rule) {
60
        $this->rules[] = $rule;
61
        return $this;
62
    }
63
64
    /**
65
     * Add a rule set.
66
     *
67
     * @param QueryBuilderRuleSetInterface $rule The rule.
68
     * @return QueryBuilderRuleSetInterface Returns this rule set.
69
     */
70
    public function addRuleSet(QueryBuilderRuleSetInterface $rule) {
71
        $this->rules[] = $rule;
72
        return $this;
73
    }
74
75
    /**
76
     * Get the condition.
77
     *
78
     * @return string Returns the condition.
79
     */
80
    public function getCondition() {
81
        return $this->condition;
82
    }
83
84
    /**
85
     * Get the rules.
86
     *
87
     * @return array Returns the rules.
88
     */
89
    public function getRules() {
90
        return $this->rules;
91
    }
92
93
    /**
94
     * Get the valid.
95
     *
96
     * @return bool Returns the valid.
97
     */
98
    public function getValid() {
99
        return $this->valid;
100
    }
101
102
    /**
103
     * Set the condition.
104
     *
105
     * @param string $condition The condition.
106
     * @return QueryBuilderRuleSetInterface Returns this rule set.
107
     * @throws InvalidArgumentException Throws an invalid argument exception if the condition is invalid.
108
     */
109
    public function setCondition($condition) {
110
        if (null !== $condition && false === in_array($condition, QueryBuilderEnumerator::enumConditions())) {
111
            throw new InvalidArgumentException(sprintf("The condition \"%s\" is invalid", $condition));
112
        }
113
        $this->condition = $condition;
114
        return $this;
115
    }
116
117
    /**
118
     * Set the rules.
119
     *
120
     * @param array $rules The rules.
121
     * @return QueryBuilderRuleSet Returns this rule set.
122
     */
123
    protected function setRules(array $rules) {
124
        $this->rules = $rules;
125
        return $this;
126
    }
127
128
    /**
129
     * Set the valid.
130
     *
131
     * @param bool $valid The valid.
132
     * @return QueryBuilderRuleSetInterface Returns this rule set.
133
     */
134
    public function setValid($valid) {
135
        $this->valid = $valid;
136
        return $this;
137
    }
138
}
139