GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AggregatorRelay::addMany()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace UCD\Unicode\Codepoint;
4
5
use UCD\Exception\InvalidArgumentException;
6
7
use UCD\Unicode\Codepoint\Aggregator\Factory;
8
use UCD\Unicode\Codepoint\AggregatorRelay\KeyGenerator;
9
use UCD\Unicode\CodepointAssigned;
10
11
class AggregatorRelay
12
{
13
    /**
14
     * @var KeyGenerator
15
     */
16
    private $keyGenerator;
17
18
    /**
19
     * @var Aggregator[]
20
     */
21
    private $aggregators = [];
22
23
    /**
24
     * @param KeyGenerator $keyGenerator
25
     */
26
    public function __construct(KeyGenerator $keyGenerator)
27
    {
28
        $this->keyGenerator = $keyGenerator;
29
    }
30
31
    /**
32
     * @param CodepointAssigned $entity
33
     * @throws InvalidArgumentException
34
     */
35
    public function add(CodepointAssigned $entity)
36
    {
37
        $aggregator = $this->getAggregatorFor($entity);
38
        $aggregator->addCodepoint($entity->getCodepoint());
39
    }
40
41
    /**
42
     * @param CodepointAssigned[] $entities
43
     */
44
    public function addMany(array $entities)
45
    {
46
        foreach ($entities as $entity) {
47
            $this->add($entity);
48
        }
49
    }
50
51
    /**
52
     * @param CodepointAssigned $entity
53
     * @return Aggregator
54
     */
55
    protected function getAggregatorFor(CodepointAssigned $entity)
56
    {
57
        $key = $this->keyGenerator->generateFor($entity);
58
59
        if (!array_key_exists($key, $this->aggregators)) {
60
            $this->aggregators[$key] = new Aggregator();
61
        }
62
63
        return $this->aggregators[$key];
64
    }
65
66
    /**
67
     * @return Range\Collection[]
68
     */
69
    public function getAllRanges()
70
    {
71
        $ranges = [];
72
73
        foreach ($this->aggregators as $key => $aggregator) {
74
            $ranges[$key] = $aggregator->getAggregated();
75
        }
76
77
        return $ranges;
78
    }
79
}