Passed
Push — 2.0-dev ( 5304ef...46e92f )
by Takehiro
02:47
created

Filter::negate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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