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

getAnnotationsFromReflection()   C

Complexity

Conditions 8
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 14
nc 2
nop 1
dl 0
loc 23
rs 6.1403
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Reflection;
4
5
use ApiGen\Contracts\Parser\Reflection\Behavior\InClassInterface;
6
use ApiGen\Contracts\Parser\Reflection\ElementReflectionInterface;
7
use TokenReflection\ReflectionAnnotation;
8
use TokenReflection\ReflectionClass;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiGen\Parser\Reflection\ReflectionClass.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use TokenReflection\ReflectionConstant;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiGen\Parser\Reflection\ReflectionConstant.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use TokenReflection\ReflectionFunction;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiGen\Parser\Reflection\ReflectionFunction.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
12
abstract class AbstractReflectionElement extends AbstractReflection implements ElementReflectionInterface
13
{
14
    /**
15
     * @var bool
16
     */
17
    protected $isDocumented;
18
19
    /**
20
     * @var mixed[]
21
     */
22
    protected $annotations;
23
24
    public function getStartPosition(): int
25
    {
26
        return $this->reflection->getStartPosition();
27
    }
28
29
    public function getEndPosition(): int
30
    {
31
        return $this->reflection->getEndPosition();
32
    }
33
34
    public function isDocumented(): bool
35
    {
36
        if ($this->isDocumented === null) {
37
            $this->isDocumented = $this->reflection->isTokenized() || $this->reflection->isInternal();
38
39
            if ($this->isDocumented) {
40
                if ($this->reflection->isInternal()) {
41
                    $this->isDocumented = false;
42
                } elseif ($this->reflection->hasAnnotation('internal')) {
43
                    $this->isDocumented = false;
44
                }
45
            }
46
        }
47
48
        return $this->isDocumented;
49
    }
50
51
    public function isDeprecated(): bool
52
    {
53
        if ($this->reflection->isDeprecated()) {
54
            return true;
55
        }
56
57
        if ($this instanceof InClassInterface) {
58
            $class = $this->getDeclaringClass();
0 ignored issues
show
Documentation Bug introduced by
The method getDeclaringClass does not exist on object<ApiGen\Parser\Ref...tractReflectionElement>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59
            return !is_null($class) && $class->isDeprecated();
60
        }
61
62
        return false;
63
    }
64
65
    public function inNamespace(): bool
66
    {
67
        return $this->getNamespaceName() !== '';
68
    }
69
70
    public function getNamespaceName(): string
71
    {
72
        static $namespaces = [];
73
74
        $namespaceName = $this->reflection->getNamespaceName();
75
76
        if (! $namespaceName) {
77
            return $namespaceName;
78
        }
79
80
        $lowerNamespaceName = strtolower($namespaceName);
81
        if (! isset($namespaces[$lowerNamespaceName])) {
82
            $namespaces[$lowerNamespaceName] = $namespaceName;
83
        }
84
85
        return $namespaces[$lowerNamespaceName];
86
    }
87
88
    public function getPseudoNamespaceName(): string
89
    {
90
        return $this->isInternal() ? 'PHP' : $this->getNamespaceName() ?: 'None';
91
    }
92
93
    /**
94
     * @return string[]
95
     */
96
    public function getNamespaceAliases(): array
97
    {
98
        return $this->reflection->getNamespaceAliases();
99
    }
100
101
    public function getDescription(): string
102
    {
103
        $short = $this->getShortDescription();
104
        $long = $this->reflection->getAnnotation(ReflectionAnnotation::LONG_DESCRIPTION);
105
106
        if (! empty($long)) {
107
            $short .= "\n\n" . $long;
108
        }
109
110
        return $short;
111
    }
112
113
    public function getDocComment(): string
114
    {
115
        return (string) $this->reflection->getDocComment();
116
    }
117
118
    /**
119
     * @return mixed[]
120
     */
121
    public function getAnnotations(): array
122
    {
123
        if ($this->annotations === null) {
124
            $annotations = $this->reflection->getAnnotations();
125
            $annotations = array_change_key_case($annotations, CASE_LOWER);
126
127
            unset($annotations[ReflectionAnnotation::SHORT_DESCRIPTION]);
128
            unset($annotations[ReflectionAnnotation::LONG_DESCRIPTION]);
129
130
            $annotations += $this->getAnnotationsFromReflection($this->reflection);
131
            $this->annotations = $annotations;
132
        }
133
134
        return $this->annotations;
135
    }
136
137
    /**
138
     * @return mixed[]
139
     */
140
    public function getAnnotation(string $name): array
141
    {
142
        return $this->hasAnnotation($name) ? $this->getAnnotations()[$name] : [];
143
    }
144
145
    public function hasAnnotation(string $name): bool
146
    {
147
        return isset($this->getAnnotations()[$name]);
148
    }
149
150
    /**
151
     * @param mixed $reflection
152
     * @return mixed[]
153
     */
154
    private function getAnnotationsFromReflection($reflection): array
155
    {
156
        $fileLevel = [
157
            'package' => true,
158
            'subpackage' => true,
159
            'author' => true,
160
            'license' => true,
161
            'copyright' => true
162
        ];
163
164
        $annotations = [];
165
        if ($reflection instanceof ReflectionClass || $reflection instanceof ReflectionFunction
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionFunction does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
166
            || ($reflection instanceof ReflectionConstant  && $reflection->getDeclaringClassName() === '')
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionConstant does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
167
        ) {
168
            foreach ($reflection->getFileReflection()->getAnnotations() as $name => $value) {
169
                if (isset($fileLevel[$name]) && empty($annotations[$name])) {
170
                    $annotations[$name] = $value;
171
                }
172
            }
173
        }
174
175
        return $annotations;
176
    }
177
178
    private function getShortDescription(): string
179
    {
180
        $short = $this->reflection->getAnnotation(ReflectionAnnotation::SHORT_DESCRIPTION);
181
        if (! empty($short)) {
182
            return $short;
183
        }
184
185
        if ($this instanceof ReflectionProperty || $this instanceof ReflectionConstant) {
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionConstant does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
186
            $var = $this->getAnnotation('var');
187
            [, $short] = preg_split('~\s+|$~', $var[0], 2);
188
        }
189
190
        return (string) $short;
191
    }
192
}
193