Bounds   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculate() 0 16 2
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;
11
use Hal\Component\Bounds\Result\BoundsResult;
12
use Hal\Component\Result\ResultCollection;
13
14
/**
15
 * ResultBoundary
16
 *
17
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
18
 */
19
class Bounds implements BoundsInterface {
20
21
    /**
22
     * @inheritdoc
23
     * @return \Hal\Component\Bounds\Result\ResultInterface
24
     */
25
    public function calculate(ResultCollection $collection) {
26
        $array = $collection->asArray();
27
28
        $arrayMerged = call_user_func_array('array_merge_recursive', $array);
29
30
        $min = $max = $average = $sum = array();
31
        foreach($arrayMerged as $key => $values) {
32
            $values = (array) $values;
33
            $max[$key] = max($values);
34
            $min[$key] = min($values);
35
            $sum[$key] = array_sum($values);
36
            $average[$key] = round($sum[$key] / count($values, COUNT_NORMAL),2);
37
        }
38
39
        return new BoundsResult($min, $max, $average, $sum);
40
    }
41
}