Completed
Push — master ( 3fc573...634850 )
by WEBEWEB
11:27
created

QueryBuilderRuleSet::setCondition()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
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\Rule;
13
14
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderConditionInterface;
15
use WBW\Library\Core\Exception\Argument\IllegalArgumentException;
16
17
/**
18
 * jQuery QueryBuilder rule set.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\Rule
22
 */
23
class QueryBuilderRuleSet implements QueryBuilderConditionInterface, QueryBuilderRuleInterface {
24
25
    /**
26
     * Parse.
27
     *
28
     * @param array $rules The rules.
29
     * @throws IllegalArgumentException Throws an illegal argument exception if an argument is invalid.
30
     */
31
    private function parse(array $rules = []) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
32
33
        // Check if condition exists.
34
        if (true === array_key_exists("condition", $rules)) {
35
            $this->setCondition($rules["condition"]);
36
        }
37
38
        // Check if rules exists.
39
        if (true === array_key_exists("rules", $rules)) {
40
41
            // Handle each rule.
42
            foreach ($rules["rules"] as $current) {
43
44
                // Check if condition exists.
45
                if (true === array_key_exists("condition", $current)) {
46
47
                    // Build a QueryBuilder rule set.
48
                    $this->addRule(new QueryBuilderRuleSet($current, $this->filterSet));
49
                    continue;
50
                }
51
52
                // Set the decorator.
53
                $decorator = null !== $this->filterSet ? $this->filterSet->getDecorator($current["id"]) : null;
54
55
                // Build a QueryBuilder rule.
56
                $this->addRule(new QueryBuilderRule($current, $decorator));
57
            }
58
        }
59
60
        // Check if valid exists.
61
        if (true === array_key_exists("valid", $rules)) {
62
            $this->setValid($rules["valid"]);
63
        }
64
    }
65
}
66