|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Jean-François Lépine <https://twitter.com/Halleck45> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Hal\Component\Bounds\Result; |
|
11
|
|
|
use Hal\Component\Result\ExportableInterface; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* ResultBoundary |
|
16
|
|
|
* |
|
17
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
|
18
|
|
|
*/ |
|
19
|
|
|
class BoundsResult implements ExportableInterface, ResultInterface { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Average values |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $average = array(); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Min values |
|
30
|
|
|
* |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $min = array(); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Max values |
|
37
|
|
|
* |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $max = array(); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Sums |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
private $sum = array(); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Constructor |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($min, $max, $average, $sum) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->min = $min; |
|
56
|
|
|
$this->max = $max; |
|
57
|
|
|
$this->average = $average; |
|
58
|
|
|
$this->sum = $sum; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function asArray() { |
|
65
|
|
|
return array( |
|
66
|
|
|
'average' => $this->average |
|
67
|
|
|
, 'min' => $this->min |
|
68
|
|
|
, 'max' => $this->max |
|
69
|
|
|
, 'sum' => $this->sum |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @inheritdoc |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getAverage($key) { |
|
77
|
|
|
return isset($this->average[$key]) ? $this->average[$key] : null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritdoc |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getMin($key) { |
|
84
|
|
|
return isset($this->min[$key]) ? $this->min[$key] : null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @inheritdoc |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getMax($key) { |
|
91
|
|
|
return isset($this->max[$key]) ? $this->max[$key] : null; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @inheritdoc |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getSum($key) { |
|
98
|
|
|
return isset($this->sum[$key]) ? $this->sum[$key] : null; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @inheritdoc |
|
103
|
|
|
*/ |
|
104
|
|
|
public function has($key) { |
|
105
|
|
|
return isset($this->sum[$key]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @inheritdoc |
|
110
|
|
|
*/ |
|
111
|
|
|
public function get($type, $key) |
|
112
|
|
|
{ |
|
113
|
|
|
switch($type) { |
|
114
|
|
|
case 'max': |
|
115
|
|
|
return $this->getMax($key); |
|
116
|
|
|
case 'sum': |
|
117
|
|
|
return $this->getSum($key); |
|
118
|
|
|
case 'min': |
|
119
|
|
|
return $this->getMin($key); |
|
120
|
|
|
case 'average': |
|
121
|
|
|
return $this->getAverage($key); |
|
122
|
|
|
} |
|
123
|
|
|
return null; |
|
124
|
|
|
} |
|
125
|
|
|
} |