Passed
Push — 2.0-dev ( 26a24f...016e30 )
by Takehiro
02:41
created

Stats::operatorOr()   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 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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 26
    public function __construct()
16
    {
17 26
        $this->reset();
18 26
    }
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 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 のフィルタ設定
36
     *
37
     * @param string $column カラム名
38
     * @param string $value フィルタする値
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 のフィルタ設定
50
     *
51
     * @param string $column カラム名
52
     * @param string $value フィルタする値
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 1
    public function sum($column)
63
    {
64 1
        return $this->set(
65 1
            sprintf("%s %s", 'sum', $column)
66 1
        );
67
    }
68
69 3
    public function min($column)
70
    {
71 3
        return $this->set(
72 3
            sprintf("%s %s", 'min', $column)
73 3
        );
74
    }
75
76 3
    public function max($column)
77
    {
78 3
        return $this->set(
79 3
            sprintf("%s %s", 'max', $column)
80 3
        );
81
    }
82
83 3
    public function avg($column)
84
    {
85 3
        return $this->set(
86 3
            sprintf("%s %s", 'avg', $column)
87 3
        );
88
    }
89
90 1
    public function std($column)
91
    {
92 1
        return $this->set(
93 1
            sprintf("%s %s", 'std', $column)
94 1
        );
95
    }
96
97 1
    public function suminv($column)
98
    {
99 1
        return $this->set(
100 1
            sprintf("%s %s", 'suminv', $column)
101 1
        );
102
    }
103
104 1
    public function avginv($column)
105
    {
106 1
        return $this->set(
107 1
            sprintf("%s %s", 'avginv', $column)
108 1
        );
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 3
    public function operatorAnd($and)
118
    {
119 3
        $this->stats[] = sprintf("StatsAnd: %d\n", $and);
120
121 3
        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 1
    public function operatorOr($or)
131
    {
132 1
        $this->stats[] = sprintf("StatsOr: %d\n", $or);
133
134 1
        return $this;
135
    }
136
137 1
    public function negate()
138
    {
139 1
        $this->stats[] = "StatsNegate:\n";
140
141 1
        return $this;
142
    }
143
144 26
    public function reset()
145
    {
146 26
        $this->stats = array();
147 26
    }
148
149 12
    public function get()
150
    {
151 12
        return $this->stats;
152
    }
153
}