Completed
Branch 2.0-dev (8b7d5c)
by Takehiro
02:30
created

Filter::lessEqual()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Kwkm\MkLiveStatusClient;
3
4
class Filter
5
{
6
    private $filters;
7
8
    public function __construct()
9
    {
10
        $this->reset();
11
    }
12
13
    /**
14
     * 任意のフィルタ設定
15
     *
16
     * @param string $filter
17
     * @return \Kwkm\MkLiveStatusClient\Filter
18
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
19
     */
20
    public function set($filter)
21
    {
22
        $this->filters[] = sprintf("Filter: %s\n", trim($filter));
23
24
        return $this;
25
    }
26
27
    /**
28
     * column = value のフィルタ設定
29
     *
30
     * @param string $column カラム名
31
     * @param string $value フィルタする値
32
     * @return \Kwkm\MkLiveStatusClient\Filter
33
     */
34
    public function equal($column, $value)
35
    {
36
        return $this->set(
37
            sprintf("%s = %s", $column, $value)
38
        );
39
    }
40
41
    /**
42
     * column ~ value のフィルタ設定
43
     *
44
     * @param string $column カラム名
45
     * @param string $value フィルタする値
46
     * @return \Kwkm\MkLiveStatusClient\Filter
47
     */
48
    public function match($column, $value)
49
    {
50
        return $this->set(
51
            sprintf("%s ~ %s", $column, $value)
52
        );
53
    }
54
55
    /**
56
     * column != value のフィルタ設定
57
     *
58
     * @param string $column カラム名
59
     * @param string $value フィルタする値
60
     * @return \Kwkm\MkLiveStatusClient\Filter
61
     */
62
    public function notEqual($column, $value)
63
    {
64
        return $this->set(
65
            sprintf("%s != %s", $column, $value)
66
        );
67
    }
68
69
    /**
70
     * column !~ value のフィルタ設定
71
     *
72
     * @param string $column カラム名
73
     * @param string $value フィルタする値
74
     * @return \Kwkm\MkLiveStatusClient\Filter
75
     */
76
    public function notMatch($column, $value)
77
    {
78
        return $this->set(
79
            sprintf("%s !~ %s", $column, $value)
80
        );
81
    }
82
83
    /**
84
     * column < value のフィルタ設定
85
     *
86
     * @param string $column カラム名
87
     * @param string $value フィルタする値
88
     * @return \Kwkm\MkLiveStatusClient\Filter
89
     */
90
    public function less($column, $value)
91
    {
92
        return $this->set(
93
            sprintf("%s < %s", $column, $value)
94
        );
95
    }
96
97
    /**
98
     * column > value のフィルタ設定
99
     *
100
     * @param string $column カラム名
101
     * @param string $value フィルタする値
102
     * @return \Kwkm\MkLiveStatusClient\Filter
103
     */
104
    public function greater($column, $value)
105
    {
106
        return $this->set(
107
            sprintf("%s > %s", $column, $value)
108
        );
109
    }
110
111
    /**
112
     * column <= value のフィルタ設定
113
     *
114
     * @param string $column カラム名
115
     * @param string $value フィルタする値
116
     * @return \Kwkm\MkLiveStatusClient\Filter
117
     */
118
    public function lessEqual($column, $value)
119
    {
120
        return $this->set(
121
            sprintf("%s <= %s", $column, $value)
122
        );
123
    }
124
125
    /**
126
     * column >= value のフィルタ設定
127
     *
128
     * @param string $column カラム名
129
     * @param string $value フィルタする値
130
     * @return \Kwkm\MkLiveStatusClient\Filter
131
     */
132
    public function greaterEqual($column, $value)
133
    {
134
        return $this->set(
135
            sprintf("%s >= %s", $column, $value)
136
        );
137
    }
138
139
    /**
140
     * Or の指定
141
     * @param integer $or
142
     * @return \Kwkm\MkLiveStatusClient\Filter
143
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
144
     */
145
    public function operatorOr($or)
146
    {
147
        $this->filters[] = sprintf("Or: %d\n", $or);
148
149
        return $this;
150
    }
151
152
    /**
153
     * And の指定
154
     * @param integer $and
155
     * @return \Kwkm\MkLiveStatusClient\Filter
156
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
157
     */
158
    public function operatorAnd($and)
159
    {
160
        $this->filters[] = sprintf("And: %d\n", $and);
161
162
        return $this;
163
    }
164
165
    public function reset()
166
    {
167
        $this->filters = array();
168
    }
169
170
    public function get()
171
    {
172
        return $this->filters;
173
    }
174
}
175