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 — 4.2-to-master ( ed215f )
by E
06:47
created

ElementExtractor::extractElementsByAnnotation()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 3
nop 1
dl 0
loc 35
rs 8.439
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Elements;
4
5
use ApiGen\Contracts\Parser\Elements\ElementExtractorInterface;
6
use ApiGen\Contracts\Parser\Elements\ElementFilterInterface;
7
use ApiGen\Contracts\Parser\Elements\ElementsInterface;
8
use ApiGen\Contracts\Parser\Elements\ElementSorterInterface;
9
use ApiGen\Contracts\Parser\Elements\ElementStorageInterface;
10
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
11
12
final class ElementExtractor implements ElementExtractorInterface
13
{
14
    /**
15
     * @var ElementsInterface
16
     */
17
    private $elements;
18
19
    /**
20
     * @var ElementFilterInterface
21
     */
22
    private $elementFilter;
23
24
    /**
25
     * @var ElementStorageInterface
26
     */
27
    private $elementStorage;
28
29
    /**
30
     * @var ElementSorterInterface
31
     */
32
    private $elementSorter;
33
34
    public function __construct(
35
        ElementsInterface $elements,
36
        ElementFilterInterface $elementFilter,
37
        ElementStorageInterface $elementStorage,
38
        ElementSorterInterface $elementSorter
39
    ) {
40
        $this->elements = $elements;
41
        $this->elementFilter = $elementFilter;
42
        $this->elementStorage = $elementStorage;
43
        $this->elementSorter = $elementSorter;
44
    }
45
46
    /**
47
     * @return mixed[]
48
     */
49
    public function extractElementsByAnnotation(string $annotation): array
50
    {
51
        $elements = $this->elements->getEmptyList();
52
        $elements[Elements::METHODS] = [];
53
        $elements[Elements::PROPERTIES] = [];
54
55
        foreach ($this->elementStorage->getElements() as $type => $elementList) {
56
            $elements[$type] += $this->elementFilter->filterByAnnotation($elementList, $annotation);
57
58
            if ($type === Elements::CONSTANTS || $type === Elements::FUNCTIONS) {
59
                continue;
60
            }
61
62
            foreach ($elementList as $class) {
63
                /** @var ClassReflectionInterface $class */
64
                $elements[Elements::METHODS] = $this->extractByAnnotationAndMerge(
65
                    $class->getOwnMethods(),
66
                    $annotation,
67
                    $elements[Elements::METHODS]
68
                );
69
                $elements[Elements::CONSTANTS] = $this->extractByAnnotationAndMerge(
70
                    $class->getOwnConstants(),
71
                    $annotation,
72
                    $elements[Elements::CONSTANTS]
73
                );
74
                $elements[Elements::PROPERTIES] = $this->extractByAnnotationAndMerge(
75
                    $class->getOwnProperties(),
76
                    $annotation,
77
                    $elements[Elements::PROPERTIES]
78
                );
79
            }
80
        }
81
82
        return $this->sortElements($elements);
83
    }
84
85
    /**
86
     * @param mixed[] $elements
87
     * @param string $annotation
88
     * @param mixed[] $storage
89
     * @return mixed[]
90
     */
91
    private function extractByAnnotationAndMerge(array $elements, string $annotation, array $storage): array
92
    {
93
        $foundElements = $this->elementFilter->filterByAnnotation($elements, $annotation);
94
95
        return array_merge($storage, array_values($foundElements));
96
    }
97
98
    /**
99
     * @param mixed[] $elements
100
     * @return mixed[]
101
     */
102
    private function sortElements(array $elements): array
103
    {
104
        foreach ($elements as $key => $elementList) {
105
            $this->elementSorter->sortElementsByFqn($elementList);
106
        }
107
108
        return $elements;
109
    }
110
}
111