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

SourceFilters::sourceUrl()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 12
nop 2
dl 0
loc 28
rs 6.7272
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Templating\Filters;
4
5
use ApiGen\Contracts\Configuration\ConfigurationInterface;
6
use ApiGen\Contracts\Parser\Reflection\Behavior\InClassInterface;
7
use ApiGen\Contracts\Parser\Reflection\Behavior\LinedInterface;
8
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
9
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface;
10
use ApiGen\Contracts\Parser\Reflection\ElementReflectionInterface;
11
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
12
13
final class SourceFilters extends Filters
14
{
15
    /**
16
     * @var ConfigurationInterface
17
     */
18
    private $configuration;
19
20
    public function __construct(ConfigurationInterface $configuration)
21
    {
22
        $this->configuration = $configuration;
23
    }
24
25
    public function staticFile(string $name): string
26
    {
27
        $filename = $this->configuration->getOption('destination') . '/' . $name;
28
        if (is_file($filename)) {
29
            $name .= '?' . sha1_file($filename);
30
        }
31
32
        return $name;
33
    }
34
35
    /**
36
     * @param ElementReflectionInterface $element
37
     * @param bool $withLine Include file line number into the link
38
     */
39
    public function sourceUrl(ElementReflectionInterface $element, bool $withLine = true): string
40
    {
41
        $file = '';
42
        $elementName = '';
43
44
        if ($this->isDirectUrl($element)) {
45
            $elementName = $element->getName();
46
            if ($element instanceof ClassReflectionInterface) {
47
                $file = 'class-';
48
            } elseif ($element instanceof ConstantReflectionInterface) {
49
                $file = 'constant-';
50
            } elseif ($element instanceof FunctionReflectionInterface) {
51
                $file = 'function-';
52
            }
53
        } elseif ($element instanceof InClassInterface) {
54
            $elementName = $element->getDeclaringClassName();
55
            $file = 'class-';
56
        }
57
58
        $file .= self::urlize($elementName);
59
60
        $url = sprintf($this->configuration->getOption('template')['templates']['source']['filename'], $file);
61
        if ($withLine) {
62
            $url .= $this->getElementLinesAnchor($element);
0 ignored issues
show
Documentation introduced by
$element is of type object<ApiGen\Contracts\...entReflectionInterface>, but the function expects a object<ApiGen\Contracts\...ehavior\LinedInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        }
64
65
        return $url;
66
    }
67
68
    private function isDirectUrl(ElementReflectionInterface $element): bool
69
    {
70
        if ($element instanceof ClassReflectionInterface
71
            || $element instanceof FunctionReflectionInterface
72
            || $element instanceof ConstantReflectionInterface
73
        ) {
74
            return true;
75
        }
76
77
        return false;
78
    }
79
80
    private function getElementLinesAnchor(LinedInterface $element): string
81
    {
82
        $anchor = '#' . $element->getStartLine();
83
        if ($element->getStartLine() !== $element->getEndLine()) {
84
            $anchor .= '-' . $element->getEndLine();
85
        }
86
87
        return $anchor;
88
    }
89
}
90