Stats::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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