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 (#837)
by E
07:31 queued 05:03
created

AbstractReflectionElement::getStartPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
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 126
    /**
20
     * @var mixed[]
21 126
     */
22
    protected $annotations;
23
24 4
    public function getStartPosition(): int
25
    {
26 4
        return $this->reflection->getStartPosition();
27
    }
28
29
    public function getEndPosition(): int
30 4
    {
31
        return $this->reflection->getEndPosition();
32
    }
33
34
    public function isDocumented(): bool
35 4
    {
36
        if ($this->isDocumented === null) {
37
            $this->isDocumented = $this->reflection->isTokenized() || $this->reflection->isInternal();
38 112
39
            if ($this->isDocumented) {
40 112
                if ($this->reflection->isInternal()) {
41
                    $this->isDocumented = false;
42 112
                } elseif ($this->reflection->hasAnnotation('internal')) {
43
                    $this->isDocumented = false;
44 112
                }
45 54
            }
46
        }
47
48 112
        return $this->isDocumented;
49 112
    }
50 4
51
    public function isDeprecated(): bool
52
    {
53 112
        if ($this->reflection->isDeprecated()) {
54
            return true;
55
        }
56 6
57
        if ($this instanceof InClassInterface) {
58 6
            $class = $this->getDeclaringClass();
59
            return !is_null($class) && $class->isDeprecated();
60
        }
61 2
62
        return false;
63 2
    }
64 2
65
    public function inNamespace(): bool
66 2
    {
67
        return $this->getNamespaceName() !== '';
68
    }
69
70 2
    public function getNamespaceName(): string
71
    {
72
        static $namespaces = [];
73
74
        $namespaceName = $this->reflection->getNamespaceName();
75
76 110
        if (! $namespaceName) {
77
            return $namespaceName;
78 110
        }
79 110
80 110
        $lowerNamespaceName = strtolower($namespaceName);
81
        if (! isset($namespaces[$lowerNamespaceName])) {
82 110
            $namespaces[$lowerNamespaceName] = $namespaceName;
83 110
        }
84
85 110
        return $namespaces[$lowerNamespaceName];
86 110
    }
87
88
    public function getPseudoNamespaceName(): string
89 110
    {
90
        return $this->isInternal() ? 'PHP' : $this->getNamespaceName() ?: 'None';
91
    }
92
93
    /**
94
     * @return string[]
95 3
     */
96
    public function getNamespaceAliases(): array
97 3
    {
98
        return $this->reflection->getNamespaceAliases();
99
    }
100 5
101
    public function getDescription(): string
102 5
    {
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
110
        return $short;
111
    }
112 110
113
    public function getDocComment(): string
114
    {
115
        return (string) $this->reflection->getDocComment();
116
    }
117
118
    /**
119 110
     * @return mixed[]
120 110
     */
121 1
    public function getAnnotations(): array
122
    {
123 5
        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 110
            $annotations += $this->getAnnotationsFromReflection($this->reflection);
131
            $this->annotations = $annotations;
132
        }
133 2
134
        return $this->annotations;
135 2
    }
136 2
137 1
    /**
138
     * @return mixed[]
139
     */
140 1
    public function getAnnotation(string $name): array
141
    {
142
        return $this->hasAnnotation($name) ? $this->getAnnotations()[$name] : [];
143
    }
144
145 1
    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