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.
Completed
Push — master ( 61bf69...3a1917 )
by Nicholas
03:32
created

AggregatorRelay::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
     * @param Factory $aggregatorFactory
26
     */
27
    public function __construct(KeyGenerator $keyGenerator, Factory $aggregatorFactory)
28
    {
29
        $this->keyGenerator = $keyGenerator;
30
        $this->aggregatorFactory = $aggregatorFactory;
0 ignored issues
show
Bug introduced by
The property aggregatorFactory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
    }
32
33
    /**
34
     * @param CodepointAssigned $entity
35
     * @throws InvalidArgumentException
36
     */
37
    public function add(CodepointAssigned $entity)
38
    {
39
        $aggregator = $this->getAggregatorFor($entity);
40
        $aggregator->addCodepoint($entity->getCodepoint());
41
    }
42
43
    /**
44
     * @param CodepointAssigned[] $entities
45
     */
46
    public function addMany(array $entities)
47
    {
48
        foreach ($entities as $entity) {
49
            $this->add($entity);
50
        }
51
    }
52
53
    /**
54
     * @param CodepointAssigned $entity
55
     * @return Aggregator
56
     */
57
    protected function getAggregatorFor(CodepointAssigned $entity)
58
    {
59
        $key = $this->keyGenerator->generateFor($entity);
60
61
        if (!array_key_exists($key, $this->aggregators)) {
62
            $this->aggregators[$key] = $this->aggregatorFactory->create();
63
        }
64
65
        return $this->aggregators[$key];
66
    }
67
68
    /**
69
     * @return Aggregator[]
70
     */
71
    public function getAll()
72
    {
73
        return $this->aggregators;
74
    }
75
76
    /**
77
     * @return Range\Collection[]
78
     */
79
    public function getAllRanges()
80
    {
81
        $ranges = [];
82
83
        foreach ($this->aggregators as $key => $aggregator) {
84
            $ranges[$key] = $aggregator->getAggregated();
85
        }
86
87
        return $ranges;
88
    }
89
}