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

aggregatePropertiesWith()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.2
cc 4
eloc 9
nc 6
nop 2
1
<?php
2
3
namespace UCD\Unicode\Character\Repository\Capability;
4
5
use UCD\Exception;
6
use UCD\Unicode\Character\Properties\General\Block;
7
use UCD\Unicode\Character\Properties\General\GeneralCategory;
8
use UCD\Unicode\Character\Repository\BlockNotFoundException;
9
use UCD\Unicode\Character\Repository\GeneralCategoryNotFoundException;
10
use UCD\Unicode\Codepoint\Aggregator;
11
use UCD\Unicode\Codepoint\Range;
12
use UCD\Unicode\CodepointAssigned;
13
14
trait PropertySearchByIteration
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function getCodepointsByBlock(Block $block)
20
    {
21
        $comparator = function (CodepointAssigned $item) use ($block) {
22
            return $item->getGeneralProperties()
23
                ->getBlock()
24
                ->equals($block);
25
        };
26
27
        return $this->aggregatePropertiesWith(
28
            $comparator,
29
            BlockNotFoundException::withBlock($block)
30
        );
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function getCodepointsByCategory(GeneralCategory $category)
37
    {
38
        $comparator = function (CodepointAssigned $item) use ($category) {
39
            return $item->getGeneralProperties()
40
                ->getGeneralCategory()
41
                ->equals($category);
42
        };
43
44
        return $this->aggregatePropertiesWith(
45
            $comparator,
46
            GeneralCategoryNotFoundException::withCategory($category)
47
        );
48
    }
49
50
    /**
51
     * @param callable $comparator
52
     * @param Exception $notFoundException
53
     * @return Range[]|Range\Collection
54
     * @throws Exception
55
     */
56
    private function aggregatePropertiesWith(callable $comparator, Exception $notFoundException)
57
    {
58
        $aggregator = new Aggregator();
59
60
        foreach ($this->getAll() as $item) {
61
            if (call_user_func($comparator, $item) === true) {
62
                $codepoint = $item->getCodepoint();
63
                $aggregator->addCodepoint($codepoint);
64
            }
65
        }
66
67
        if ($aggregator->hasAggregated() !== true) {
68
            throw $notFoundException;
69
        }
70
71
        return $aggregator->getAggregated();
72
    }
73
74
    /**
75
     * @return CodepointAssigned[]
76
     */
77
    abstract public function getAll();
78
}