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.

FencedCodeRenderer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\CommonMarkHighlighter;
4
5
use League\CommonMark\Block\Element\AbstractBlock;
6
use League\CommonMark\Block\Element\FencedCode;
7
use League\CommonMark\Block\Renderer\BlockRendererInterface;
8
use League\CommonMark\Block\Renderer\FencedCodeRenderer as BaseFencedCodeRenderer;
9
use League\CommonMark\ElementRendererInterface;
10
use League\CommonMark\Util\Xml;
11
12
class FencedCodeRenderer implements BlockRendererInterface
13
{
14
    /** @var \Spatie\CommonMarkHighlighter\CodeBlockHighlighter */
15
    protected $highlighter;
16
17
    /** @var \League\CommonMark\Block\Renderer\FencedCodeRenderer */
18
    protected $baseRenderer;
19
20
    public function __construct(array $autodetectLanguages = [])
21
    {
22
        $this->highlighter = new CodeBlockHighlighter($autodetectLanguages);
23
        $this->baseRenderer = new BaseFencedCodeRenderer();
24
    }
25
26
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
27
    {
28
        $element = $this->baseRenderer->render($block, $htmlRenderer, $inTightList);
29
30
        $element->setContents(
31
            $this->highlighter->highlight(
32
                $element->getContents(),
33
                $this->getSpecifiedLanguage($block)
0 ignored issues
show
Compatibility introduced by
$block of type object<League\CommonMark...\Element\AbstractBlock> is not a sub-type of object<League\CommonMark...ock\Element\FencedCode>. It seems like you assume a child class of the class League\CommonMark\Block\Element\AbstractBlock to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
34
            )
35
        );
36
37
        return $element;
38
    }
39
40
    protected function getSpecifiedLanguage(FencedCode $block): ?string
41
    {
42
        $infoWords = $block->getInfoWords();
43
44
        if (empty($infoWords) || empty($infoWords[0])) {
45
            return null;
46
        }
47
48
        return Xml::escape($infoWords[0], true);
0 ignored issues
show
Unused Code introduced by
The call to Xml::escape() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49
    }
50
}
51