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 ( 0edef5...fd3de2 )
by Nicholas
03:23
created

PropertySearchByIteration::getCodepointsByScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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