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

Stats::negate()   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 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
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 20
    public function __construct()
16
    {
17 20
        $this->reset();
18 20
    }
19
20
    /**
21
     * 任意のフィルタ設定
22
     *
23
     * @param string $stats
24
     * @return \Kwkm\MkLiveStatusClient\Stats
25
     * @throw \InvalidArgumentException if the provided argument is not of type 'string'.
26
     */
27 6
    public function set($stats)
28
    {
29 6
        $this->stats[] = sprintf("Stats: %s\n", trim($stats));
30
31 6
        return $this;
32
    }
33
34
    /**
35
     * column = value のフィルタ設定
36
     *
37
     * @param string $column カラム名
38
     * @param string $value フィルタする値
39
     * @return \Kwkm\MkLiveStatusClient\Stats
40
     */
41 6
    public function equal($column, $value)
42
    {
43 6
        return $this->set(
44 6
            sprintf("%s = %s", $column, $value)
45 6
        );
46
    }
47
48
    /**
49
     * column != value のフィルタ設定
50
     *
51
     * @param string $column カラム名
52
     * @param string $value フィルタする値
53
     * @return \Kwkm\MkLiveStatusClient\Stats
54
     */
55
    public function notEqual($column, $value)
56
    {
57
        return $this->set(
58
            sprintf("%s != %s", $column, $value)
59
        );
60
    }
61
62
    public function sum($column)
63
    {
64
        return $this->set(
65
            sprintf("%s %s", 'sum', $column)
66
        );
67
    }
68
69
    public function min($column)
70
    {
71
        return $this->set(
72
            sprintf("%s %s", 'min', $column)
73
        );
74
    }
75
76
    public function max($column)
77
    {
78
        return $this->set(
79
            sprintf("%s %s", 'max', $column)
80
        );
81
    }
82
83
    public function avg($column)
84
    {
85
        return $this->set(
86
            sprintf("%s %s", 'avg', $column)
87
        );
88
    }
89
90
    public function std($column)
91
    {
92
        return $this->set(
93
            sprintf("%s %s", 'std', $column)
94
        );
95
    }
96
97
    public function suminv($column)
98
    {
99
        return $this->set(
100
            sprintf("%s %s", 'suminv', $column)
101
        );
102
    }
103
104
    public function avginv($column)
105
    {
106
        return $this->set(
107
            sprintf("%s %s", 'avginv', $column)
108
        );
109
    }
110
111
    /**
112
     * StatsAnd の指定
113
     * @param integer $and
114
     * @return \Kwkm\MkLiveStatusClient\Stats
115
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
116
     */
117 2
    public function operatorAnd($and)
118
    {
119 2
        $this->stats[] = sprintf("StatsAnd: %d\n", $and);
120
121 2
        return $this;
122
    }
123
124
    /**
125
     * StatsOr の指定
126
     * @param integer $or
127
     * @return \Kwkm\MkLiveStatusClient\Stats
128
     * @throw \InvalidArgumentException if the provided argument is not of type 'integer'.
129
     */
130
    public function operatorOr($or)
131
    {
132
        $this->stats[] = sprintf("StatsOr: %d\n", $or);
133
134
        return $this;
135
    }
136
137
    public function negate()
138
    {
139
        $this->stats[] = "StatsNegate:\n";
140
141
        return $this;
142
    }
143
144 20
    public function reset()
145
    {
146 20
        $this->stats = array();
147 20
    }
148
149 6
    public function get()
150
    {
151 6
        return $this->stats;
152
    }
153
}