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

ReflectionParameter::getTypeHint()   C

Complexity

Conditions 8
Paths 7

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 15
nc 7
nop 0
dl 0
loc 27
rs 5.3846
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\AbstractFunctionMethodReflectionInterface;
6
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
7
use ApiGen\Contracts\Parser\Reflection\ParameterReflectionInterface;
8
9
final class ReflectionParameter extends AbstractReflection implements ParameterReflectionInterface
10
{
11
    public function getTypeHint(): string
12
    {
13
        if ($this->isArray()) {
14
            return 'array';
15
        }
16
17
        if ($this->isCallable()) {
18
            return 'callable';
19
        }
20
21
        $className = $this->getClassName();
22
        if ($className) {
23
            return $className;
24
        }
25
26
        $annotations = $this->getDeclaringFunction()->getAnnotation('param');
27
        if ($annotations) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $annotations of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
28
            if (! empty($annotations[$this->getPosition()])) {
29
                [$types] = preg_split('~\s+|$~', $annotations[$this->getPosition()], 2);
0 ignored issues
show
Bug introduced by
The variable $types does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
                if (! empty($types) && $types[0] !== '$') {
31
                    return $types;
32
                }
33
            }
34
        }
35
36
        return '';
37
    }
38
39
    public function getDescription(): string
40
    {
41
        $annotations = $this->getDeclaringFunction()->getAnnotation('param');
42
        if (empty($annotations[$this->getPosition()])) {
43
            return '';
44
        }
45
46
        $description = trim(strpbrk($annotations[$this->getPosition()], "\n\r\t "));
47
        return preg_replace('~^(\\$' . $this->getName() . '(?:,\\.{3})?)(\\s+|$)~i', '\\2', $description, 1);
48
    }
49
50
    public function getDefaultValueDefinition(): ?string
51
    {
52
        return $this->reflection === null ? null : $this->reflection->getDefaultValueDefinition();
53
    }
54
55
    public function isDefaultValueAvailable(): bool
56
    {
57
        return $this->reflection->isDefaultValueAvailable();
58
    }
59
60
    public function getPosition(): int
61
    {
62
        return $this->reflection->getPosition();
63
    }
64
65
    public function isArray(): bool
66
    {
67
        return $this->reflection->isArray();
68
    }
69
70
    public function isCallable(): bool
71
    {
72
        return $this->reflection->isCallable();
73
    }
74
75
    public function getClass(): ?ClassReflectionInterface
76
    {
77
        $className = (string) $this->reflection->getClassName();
78
        return $className === '' ? null : $this->getParsedClasses()[$className];
79
    }
80
81
    public function getClassName(): ?string
82
    {
83
        return $this->reflection->getClassName();
84
    }
85
86
    public function allowsNull(): bool
87
    {
88
        return $this->reflection->allowsNull();
89
    }
90
91
    public function isOptional(): bool
92
    {
93
        return $this->reflection->isOptional();
94
    }
95
96
    public function isPassedByReference(): bool
97
    {
98
        return $this->reflection->isPassedByReference();
99
    }
100
101
    public function canBePassedByValue(): bool
102
    {
103
        return $this->reflection->canBePassedByValue();
104
    }
105
106
    public function getDeclaringFunction(): AbstractFunctionMethodReflectionInterface
107
    {
108
        $functionName = $this->reflection->getDeclaringFunctionName();
109
110
        $className = $this->reflection->getDeclaringClassName();
111
112
        if ($className) {
113
            return $this->getParsedClasses()[$className]->getMethod($functionName);
114
        }
115
116
        return $this->parserStorage->getFunctions()[$functionName];
117
    }
118
119
    public function getDeclaringFunctionName(): string
120
    {
121
        return (string) $this->reflection->getDeclaringFunctionName();
122
    }
123
124
    public function getDeclaringClass(): ?ClassReflectionInterface
125
    {
126
        $className = $this->reflection->getDeclaringClassName();
127
        return $className === '' ? null : $this->getParsedClasses()[$className];
128
    }
129
130
    public function getDeclaringClassName(): string
131
    {
132
        return (string) $this->reflection->getDeclaringClassName();
133
    }
134
135
    public function isUnlimited(): bool
136
    {
137
        return false;
138
    }
139
}
140