Aggregator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A aggregate() 0 15 4
1
<?php
2
3
namespace Dwo\Aggregator;
4
5
use Dwo\Aggregator\Collector\Collector;
6
use Dwo\Aggregator\Collector\IdCollector;
7
use Dwo\Aggregator\Model\Aggregate;
8
use Dwo\Aggregator\Model\AggregateGroup;
9
use Dwo\Aggregator\Model\PreAggregateGroup;
10
11
/**
12
 * Class Aggregator
13
 *
14
 * @author Dave Www <[email protected]>
15
 */
16
class Aggregator
17
{
18
    /**
19
     * @param Collector|PreAggregateGroup[] $collector
20
     * @param array                         $saveKeys
21
     *
22
     * @return AggregateGroup
23
     */
24
    public static function aggregate(Collector $collector, array $saveKeys = [])
25
    {
26
        $idKey = $collector instanceof IdCollector ? $collector->getIdKey() : null;
27
28
        $group = new AggregateGroup();
29
        foreach ($collector as $groupKey => $preAggregateGroup) {
30
            $group->addAggregate($aggregate = new Aggregate($preAggregateGroup->getGroup()));
31
            foreach ($preAggregateGroup as $preAggregate) {
32
                Merger::merge($aggregate, $preAggregate, $saveKeys, $idKey);
33
            }
34
            Operator::operation($aggregate, $saveKeys);
35
        }
36
37
        return $group;
38
    }
39
}