Passed
Push — master ( 34488c...4ee1ca )
by Maxim
02:53 queued 11s
created

Avg   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 3
1
<?php
2
/**
3
 * @author Igor Pomiluyko <[email protected]>
4
 */
5
6
namespace WS\Utils\Collections\Functions\Group\Aggregator;
7
8
use WS\Utils\Collections\Collection;
9
10
class Avg extends AbstractFieldAggregator implements Aggregator
11
{
12
13 8
    public function __invoke(Collection $collection)
14
    {
15 8
        $acc = null;
16 8
        $cnt = 0;
17 8
        foreach ($collection as $element) {
18 7
            $acc += $this->getValue($element);
19 6
            $cnt++;
20
        }
21 7
        if (!$cnt) {
22 1
            return null;
23
        }
24 6
        return $acc / $cnt;
25
    }
26
}
27