Passed
Push — 2.0-dev ( 039993...c965cf )
by Takehiro
02:35
created

LqlBuilder::__call()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 34
Code Lines 18

Duplication

Lines 28
Ratio 82.35 %

Code Coverage

Tests 19
CRAP Score 7.0422

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 28
loc 34
ccs 19
cts 21
cp 0.9048
rs 6.7272
cc 7
eloc 18
nc 5
nop 2
crap 7.0422
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\Lql
16
     */
17
    private $lql;
18
19
    /**
20
     * @var \Kwkm\MkLiveStatusClient\Column
21
     */
22
    private $column;
23
24
    /**
25
     * @var \Kwkm\MkLiveStatusClient\Filter
26
     */
27
    private $filter;
28
29
    /**
30
     * @var \Kwkm\MkLiveStatusClient\Stats
31
     */
32
    private $stats;
33
34
    /**
35
     * 初期化
36
     *
37
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
38
     */
39 17
    public function reset()
40
    {
41 17
        $this->lql->reset();
42 17
        $this->column = new Column();
43 17
        $this->filter = new Filter();
44 17
        $this->stats = new Stats();
45
46 17
        return $this;
47
    }
48
49 14
    public function __call($method, $arguments)
50
    {
51 14 View Code Duplication
        if (substr($method, 0, 5) === 'stats') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
52 3
            $callMethod = lcfirst(substr($method, 5));
53
54 3
            if (($callMethod === 'or') || ($callMethod === 'and')) {
55 1
                $callMethod = 'operator' . ucfirst($callMethod);
56 1
            }
57
58 3
            call_user_func_array(array($this->stats, $callMethod), $arguments);
59
60 3
            $this->lql->stats($this->stats);
61 3
            $this->stats->reset();
62
63 3
            return $this;
64
        }
65
66 13 View Code Duplication
        if (substr($method, 0, 6) === 'filter') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
67 13
            $callMethod = lcfirst(substr($method, 6));
68
69 13
            if (($callMethod === 'or') || ($callMethod === 'and')) {
70 4
                $callMethod = 'operator' . ucfirst($callMethod);
71 4
            }
72
73 13
            call_user_func_array(array($this->filter, $callMethod), $arguments);
74
75 13
            $this->lql->filter($this->filter);
76 13
            $this->filter->reset();
77
78 13
            return $this;
79
        }
80
81
        trigger_error('Call to undefined method ' . get_class($this) . '::' . $method, E_USER_ERROR);
82
    }
83
84
    /**
85
     * 取得カラムの指定
86
     *
87
     * @param string $column
88
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
89
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
90
     */
91 2
    public function column($column)
92
    {
93 2
        $this->column->add($column);
94 2
        $this->lql->column($this->column);
95
96 2
        return $this;
97
    }
98
99
    /**
100
     * ヘッダ情報を取得するかの設定
101
     *
102
     * @param boolean $boolean
103
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
104
     * @throw \InvalidArgumentException if the provided argument is not of type 'boolean'.
105
     */
106
    public function headers($boolean)
107
    {
108
        $this->lql->headers($boolean);
109
110
        return $this;
111
    }
112
113
    /**
114
     * 取得カラムの一括指定
115
     *
116
     * @param array $columns
117
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
118
     * @throw \InvalidArgumentException if the provided argument is not of type 'array'.
119
     */
120 7
    public function columns($columns)
121
    {
122 7
        $this->column = new Column($columns);
123 7
        $this->lql->column($this->column);
124
125 7
        return $this;
126
    }
127
128
    /**
129
     * StatsNegate の指定
130
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
131
     */
132
    public function statsNegate()
133
    {
134
        $this->lql->statsNegate();
135
136
        return $this;
137
    }
138
139
    /**
140
     * Negate の指定
141
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
142
     */
143 1
    public function negate()
144
    {
145 1
        $this->lql->negate();
146
147 1
        return $this;
148
    }
149
150
    /**
151
     * パラメータの指定
152
     * @param string $parameter
153
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
154
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
155
     */
156
    public function parameter($parameter)
157
    {
158
        $this->lql->parameter($parameter);
159
160
        return $this;
161
    }
162
163
    /**
164
     * OutputFormat の指定
165
     * @param string $outputFormat
166
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
167
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
168
     */
169
    public function outputFormat($outputFormat)
170
    {
171
        $this->lql->outputFormat($outputFormat);
172
173
        return $this;
174
    }
175
176
    /**
177
     * Limit の指定
178
     * @param integer $limit
179
     * @return \Kwkm\MkLiveStatusClient\LqlBuilder
180
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
181
     */
182
    public function limit($limit)
183
    {
184
        $this->lql->limit($limit);
185
186
        return $this;
187
    }
188
189
    /**
190
     * Lqlの実行テキストの作成
191
     * @return string
192
     */
193 17
    public function build()
194
    {
195 17
        return $this->lql->build();
196
    }
197
198
    /**
199
     * コンストラクタ
200
     */
201 17
    public function __construct($table, $authUser = null)
202
    {
203 17
        $this->lql = new Lql($table, $authUser);
204 17
        $this->reset();
205 17
    }
206
}
207