IdCollector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getIdKey() 0 4 1
A addEntry() 0 8 1
A getIds() 0 4 1
A getById() 0 4 2
1
<?php
2
3
namespace Dwo\Aggregator\Collector;
4
5
use Dwo\Aggregator\Model\PreAggregate;
6
7
/**
8
 * Class IdCollector
9
 *
10
 * @author Dave Www <[email protected]>
11
 */
12
class IdCollector extends Collector
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $idKey;
18
19
    /**
20
     * @var PreAggregate[]
21
     */
22
    protected $idEntries;
23
24
    /**
25
     * @param array  $groupKeys
26
     * @param string $idKey
27
     */
28
    public function __construct(array $groupKeys, $idKey)
29
    {
30
        parent::__construct($groupKeys);
31
        $this->idKey = $idKey;
32
        $this->idEntries = [];
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getIdKey()
39
    {
40
        return $this->idKey;
41
    }
42
43
    /**
44
     * :TODO: maybe countKey instead of $inc
45
     *
46
     * @param mixed $entry
47
     * @param int   $inc
48
     */
49
    public function addEntry($entry, $inc = 1)
50
    {
51
        $id = $entry[$this->getIdKey()];
52
53
        $this->idEntries[$id] = $entry = new PreAggregate($entry, $id, $inc);
54
55
        parent::addEntry($entry, $inc);
56
    }
57
58
    /**
59
     * :TODO: rename
60
     *
61
     * @return PreAggregate[]
62
     */
63
    public function getIds()
64
    {
65
        return $this->idEntries;
66
    }
67
68
    /**
69
     * @param string $id
70
     *
71
     * @return PreAggregate
72
     */
73
    public function getById($id)
74
    {
75
        return isset($this->idEntries[$id]) ? $this->idEntries[$id] : null;
76
    }
77
}