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

QueryBuilderRule::setDecorator()   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\Model;
13
14
use InvalidArgumentException;
15
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderDecoratorInterface;
16
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderOperatorInterface;
17
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderRuleInterface;
18
19
/**
20
 * QueryBuilder rule.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\Model
24
 */
25
class QueryBuilderRule extends AbstractQueryBuilder implements QueryBuilderOperatorInterface, QueryBuilderRuleInterface {
26
27
    /**
28
     * Decorator.
29
     *
30
     * @var QueryBuilderDecoratorInterface|null
31
     */
32
    private $decorator;
33
34
    /**
35
     * Operator.
36
     *
37
     * @var string|null
38
     */
39
    private $operator;
40
41
    /**
42
     * Value.
43
     *
44
     * @var mixed
45
     */
46
    private $value;
47
48
    /**
49
     * Constructor.
50
     */
51
    public function __construct() {
52
        parent::__construct();
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function getDecorator(): ?QueryBuilderDecoratorInterface {
59
        return $this->decorator;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65
    public function getOperator(): ?string {
66
        return $this->operator;
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function getValue() {
73
        return $this->value;
74
    }
75
76
    /**
77
     * Set the decorator.
78
     *
79
     * @param QueryBuilderDecoratorInterface|null $decorator The decorator.
80
     * @return QueryBuilderRuleInterface Returns this rule.
81
     */
82
    public function setDecorator(?QueryBuilderDecoratorInterface $decorator): QueryBuilderRuleInterface {
83
        $this->decorator = $decorator;
84
        return $this;
85
    }
86
87
    /**
88
     * Set the operator.
89
     *
90
     * @param string|null $operator The operator.
91
     * @return QueryBuilderRuleInterface Returns this rule.
92
     * @throws InvalidArgumentException Throws an invalid argument exception if the operator is invalid.
93
     */
94
    public function setOperator(?string $operator): QueryBuilderRuleInterface {
95
        if (null !== $operator && false === array_key_exists($operator, QueryBuilderEnumerator::enumOperators())) {
96
            throw new InvalidArgumentException(sprintf('The operator "%s" is invalid', $operator));
97
        }
98
        $this->operator = $operator;
99
        return $this;
100
    }
101
102
    /**
103
     * Set the value.
104
     *
105
     * @param mixed $value The value.
106
     * @return QueryBuilderRuleInterface Returns this rule.
107
     */
108
    public function setValue($value): QueryBuilderRuleInterface {
109
        $this->value = $value;
110
        return $this;
111
    }
112
}
113