Passed
Push — 2.0-dev ( ea71a8...6bc26c )
by Takehiro
03:10
created

LqlBuilder::filterNotEqual()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Kwkm\MkLiveStatusClient;
4
5
/**
6
 * Class LqlBuilder
7
 *
8
 * @package Kwkm\MkLiveStatusClient
9
 * @author Takehiro Kawakami <[email protected]>
10
 * @license MIT
11
 */
12
class LqlBuilder extends LqlAbstract
13
{
14
    /**
15
     * @var \Kwkm\MkLiveStatusClient\LqlObject
16
     */
17
    private $lqlObject;
18
19
    /**
20
     * @var string
21
     */
22
    private $table;
23
24
    /**
25
     * @var string
26
     */
27
    private $authUser;
28
29
    /**
30
     * 初期化
31
     *
32
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
33
     */
34 5 View Code Duplication
    public function reset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36 5
        $this->lqlObject = new LqlObject();
37 5
        $this->lqlObject->setTable($this->table);
38 5
        if (!is_null($this->authUser)) {
39 1
            $this->lqlObject->setAuthUser($this->authUser);
40 1
        }
41
42 5
        return $this;
43
    }
44
45
    /**
46
     * 取得カラムの指定
47
     *
48
     * @param string $column
49
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
50
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
51
     */
52 1
    public function column($column)
53
    {
54 1
        $this->lqlObject->appendColumns($column);
55
56 1
        return $this;
57
    }
58
59
    /**
60
     * ヘッダ情報を取得するかの設定
61
     *
62
     * @param boolean $boolean
63
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
64
     * @throw \InvalidArgumentException if the provided argument is not of type 'boolean'.
65
     */
66
    public function headers($boolean)
67
    {
68
        $this->lqlObject->setHeader($boolean);
69
70
        return $this;
71
    }
72
73
    /**
74
     * 取得カラムの一括指定
75
     *
76
     * @param array $columns
77
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
78
     * @throw \InvalidArgumentException if the provided argument is not of type 'array'.
79
     */
80 3
    public function columns($columns)
81
    {
82 3
        $this->lqlObject->setColumns($columns);
83
84 3
        return $this;
85
    }
86
87
    /**
88
     * 任意のフィルタ設定
89
     *
90
     * @param string $filter
91
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
92
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
93
     */
94 2
    public function filter($filter)
95
    {
96 2
        $this->lqlObject->appendStringQuery('Filter', $filter);
97
98 2
        return $this;
99
    }
100
101
    /**
102
     * column = value のフィルタ設定
103
     *
104
     * @param string $column カラム名
105
     * @param string $value フィルタする値
106
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
107
     */
108 2
    public function filterEqual($column, $value)
109
    {
110 2
        return $this->filter(
111 2
            sprintf("%s = %s", $column, $value)
112 2
        );
113
    }
114
115
    /**
116
     * column ~ value のフィルタ設定
117
     *
118
     * @param string $column カラム名
119
     * @param string $value フィルタする値
120
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
121
     */
122
    public function filterMatch($column, $value)
123
    {
124
        return $this->filter(
125
            sprintf("%s ~ %s", $column, $value)
126
        );
127
    }
128
129
    /**
130
     * column != value のフィルタ設定
131
     *
132
     * @param string $column カラム名
133
     * @param string $value フィルタする値
134
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
135
     */
136
    public function filterNotEqual($column, $value)
137
    {
138
        return $this->filter(
139
            sprintf("%s != %s", $column, $value)
140
        );
141
    }
142
143
    /**
144
     * column !~ value のフィルタ設定
145
     *
146
     * @param string $column カラム名
147
     * @param string $value フィルタする値
148
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
149
     */
150
    public function filterNotMatch($column, $value)
151
    {
152
        return $this->filter(
153
            sprintf("%s !~ %s", $column, $value)
154
        );
155
    }
156
157
    /**
158
     * column < value のフィルタ設定
159
     *
160
     * @param string $column カラム名
161
     * @param string $value フィルタする値
162
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
163
     */
164
    public function filterLess($column, $value)
165
    {
166
        return $this->filter(
167
            sprintf("%s < %s", $column, $value)
168
        );
169
    }
170
171
    /**
172
     * column > value のフィルタ設定
173
     *
174
     * @param string $column カラム名
175
     * @param string $value フィルタする値
176
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
177
     */
178
    public function filterGreater($column, $value)
179
    {
180
        return $this->filter(
181
            sprintf("%s > %s", $column, $value)
182
        );
183
    }
184
185
    /**
186
     * column <= value のフィルタ設定
187
     *
188
     * @param string $column カラム名
189
     * @param string $value フィルタする値
190
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
191
     */
192
    public function filterLessEqual($column, $value)
193
    {
194
        return $this->filter(
195
            sprintf("%s <= %s", $column, $value)
196
        );
197
    }
198
199
    /**
200
     * column >= value のフィルタ設定
201
     *
202
     * @param string $column カラム名
203
     * @param string $value フィルタする値
204
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
205
     */
206
    public function filterGreaterEqual($column, $value)
207
    {
208
        return $this->filter(
209
            sprintf("%s >= %s", $column, $value)
210
        );
211
    }
212
213
    /**
214
     * Stats の指定
215
     * @param string $stats
216
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
217
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
218
     */
219
    public function stats($stats)
220
    {
221
        $this->lqlObject->appendStringQuery('Stats', $stats);
222
223
        return $this;
224
    }
225
226
    /**
227
     * column = value のStats設定
228
     *
229
     * @param string $column カラム名
230
     * @param string $value フィルタする値
231
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
232
     */
233
    public function statsEqual($column, $value)
234
    {
235
        return $this->stats(
236
            sprintf("%s = %s", $column, $value)
237
        );
238
    }
239
240
    /**
241
     * column != value のStats設定
242
     *
243
     * @param string $column カラム名
244
     * @param string $value フィルタする値
245
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
246
     */
247
    public function statsNotEqual($column, $value)
248
    {
249
        return $this->filter(
250
            sprintf("%s != %s", $column, $value)
251
        );
252
    }
253
254
    /**
255
     * StatsAnd の指定
256
     * @param integer $statsAnd
257
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
258
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
259
     */
260
    public function statsAnd($statsAnd)
261
    {
262
        $this->lqlObject->appendIntegerQuery('StatsAnd', $statsAnd);
263
264
        return $this;
265
    }
266
267
    /**
268
     * StatsNegate の指定
269
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
270
     */
271
    public function statsNegate()
272
    {
273
        $this->lqlObject->appendNoValueQuery('StatsNegate');
274
275
        return $this;
276
    }
277
278
    /**
279
     * Or の指定
280
     * @param integer $or
281
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
282
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
283
     */
284
    public function filterOr($or)
285
    {
286
        $this->lqlObject->appendIntegerQuery('Or', $or);
287
288
        return $this;
289
    }
290
291
    /**
292
     * And の指定
293
     * @param integer $and
294
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
295
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
296
     */
297
    public function filterAnd($and)
298
    {
299
        $this->lqlObject->appendIntegerQuery('And', $and);
300
301
        return $this;
302
    }
303
304
    /**
305
     * Negate の指定
306
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
307
     */
308
    public function negate()
309
    {
310
        $this->lqlObject->appendNoValueQuery('Negate');
311
312
        return $this;
313
    }
314
315
    /**
316
     * パラメータの指定
317
     * @param string $parameter
318
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
319
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
320
     */
321
    public function parameter($parameter)
322
    {
323
        $this->lqlObject->appendParameter($parameter);
324
325
        return $this;
326
    }
327
328
    /**
329
     * OutputFormat の指定
330
     * @param string $outputFormat
331
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
332
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
333
     */
334
    public function outputFormat($outputFormat)
335
    {
336
        $this->lqlObject->setOutputFormat($outputFormat);
337
338
        return $this;
339
    }
340
341
    /**
342
     * Limit の指定
343
     * @param integer $limit
344
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
345
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
346
     */
347
    public function limit($limit)
348
    {
349
        $this->lqlObject->setLimit($limit);
350
351
        return $this;
352
    }
353
354
    /**
355
     * Lqlの実行テキストの作成
356
     * @return string
357
     */
358 5
    public function build()
359
    {
360 5
        return $this->lqlObject->build();
361
    }
362
363
    /**
364
     * コンストラクタ
365
     */
366 5
    public function __construct($table, $authUser = null)
367
    {
368 5
        $this->table = $table;
369 5
        $this->authUser = $authUser;
370 5
        $this->reset();
371 5
    }
372
}
373