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.

PropertySearchByIteration   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 10
dl 0
loc 82
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCodepointsByBlock() 0 13 1
A getCodepointsByCategory() 0 13 1
A getCodepointsByScript() 0 13 1
A aggregatePropertiesWith() 0 17 4
getAll() 0 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
}