FilterOperation::setOperator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 3
nop 1
crap 1
1
<?php
2
3
namespace Nayjest\Querying\Operation;
4
5
/**
6
 * DataProvider operation for filtering rows.
7
 */
8
class FilterOperation implements OperationInterface{
9
10
    const OPERATOR_LIKE = 'like';
11
    const OPERATOR_STR_STARTS_WITH = 'str_starts_with';
12
    const OPERATOR_STR_ENDS_WITH = 'str_ends_with';
13
    const OPERATOR_STR_CONTAINS = 'str_contains';
14
    const OPERATOR_EQ = '=';
15
    const OPERATOR_NOT_EQ = '<>';
16
    const OPERATOR_GT = '>';
17
    const OPERATOR_LT = '<';
18
    const OPERATOR_LTE = '<=';
19
    const OPERATOR_GTE = '>=';
20
21
    protected $field;
22
23
    protected $value;
24
25
    protected $operator;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param string|null $field name of data field to filter rows by its value
31
     * @param string|null $operator
32
     * @param mixed $value
33
     */
34 3
    public function __construct(
35
        $field = null,
36
        $operator = self::OPERATOR_EQ,
37
        $value = null
38
    ) {
39 3
        $this->setField($field);
40 3
        $this->setValue($value);
41 3
        $this->setOperator($operator);
42 3
    }
43
44
    /**
45
     * Returns name of data field to filter rows by its value.
46
     *
47
     * @return string
48
     */
49 3
    public function getField()
50
    {
51 3
        return $this->field;
52
    }
53
54
    /**
55
     * Sets name of data field to filter rows by its value.
56
     *
57
     * @param $field
58
     * @return $this
59
     */
60 3
    public function setField($field)
61
    {
62 3
        $this->field = $field;
63 3
        return $this;
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69 3
    public function getValue()
70
    {
71 3
        return $this->value;
72
    }
73
74
    /**
75
     * @param mixed $value
76
     * @return $this
77
     */
78 3
    public function setValue($value)
79
    {
80 3
        $this->value = $value;
81 3
        return $this;
82
    }
83
84
    /**
85
     * @return string
86
     */
87 3
    public function getOperator()
88
    {
89 3
        return $this->operator;
90
    }
91
92
    /**
93
     * @param $operator
94
     * @return $this
95
     */
96 3
    public function setOperator($operator)
97
    {
98 3
        $this->operator = $operator;
99 3
        return $this;
100
    }
101
}
102