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
Pull Request — master (#723)
by Mark
16:08
created

AutocompleteElements::processElement()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 6
eloc 11
c 3
b 0
f 0
nc 7
nop 1
dl 0
loc 19
rs 8.8571
1
<?php
2
3
/**
4
 * This file is part of the ApiGen (http://apigen.org)
5
 *
6
 * For the full copyright and license information, please view
7
 * the file LICENSE that was distributed with this source code.
8
 */
9
10
namespace ApiGen\Parser\Elements;
11
12
use ApiGen\Contracts\Parser\Elements\AutocompleteElementsInterface;
13
use ApiGen\Contracts\Parser\Elements\ElementStorageInterface;
14
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
15
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface;
16
use ApiGen\Contracts\Parser\Reflection\ElementReflectionInterface;
17
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
18
use ApiGen\Parser\Reflection\ReflectionBase;
19
use ApiGen\Parser\Reflection\ReflectionClass;
20
use ApiGen\Parser\Reflection\ReflectionConstant;
21
use ApiGen\Parser\Reflection\ReflectionFunction;
22
23
class AutocompleteElements implements AutocompleteElementsInterface
24
{
25
26
    /**
27
     * @var ElementStorageInterface
28
     */
29
    private $elementStorage;
30
31
    /**
32
     * @var array
33
     */
34
    private $elements = [];
35
36
37
    public function __construct(ElementStorageInterface $elementStorage)
38
    {
39
        $this->elementStorage = $elementStorage;
40
    }
41
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getElements()
47
    {
48
        foreach ($this->elementStorage->getElements() as $type => $elementList) {
49
            foreach ($elementList as $element) {
50
                $this->processElement($element);
51
            }
52
        }
53
54
        $this->sortElements();
55
56
        return $this->elements;
57
    }
58
59
60
    private function processElement(ElementReflectionInterface $element)
61
    {
62
        if ($element instanceof ConstantReflectionInterface) {
63
            $this->elements[] = ['co', $element->getPrettyName()];
64
65
        } elseif ($element instanceof FunctionReflectionInterface) {
66
            $this->elements[] = ['f', $element->getPrettyName()];
67
68
        } elseif ($element instanceof ClassReflectionInterface) {
69
            $this->elements[] = ['c', $element->getPrettyName()];
70
71
            foreach ($element->getOwnMethods() as $method) {
72
                $this->elements[] = ['m', $method->getPrettyName()];
73
            }
74
            foreach ($element->getOwnProperties() as $property) {
75
                $this->elements[] = ['p', $property->getPrettyName()];
76
            }
77
        }
78
    }
79
80
81
    private function sortElements()
82
    {
83
        usort($this->elements, function ($one, $two) {
84
            return strcasecmp($one[1], $two[1]);
85
        });
86
    }
87
}
88