Test Failed
Push — develop ( 32ca41...230235 )
by Brent
04:59
created

ExternalLinkRenderer::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 24
ccs 0
cts 13
cp 0
crap 12
rs 9.536
c 0
b 0
f 0
1
<?php
2
3
namespace Pageon\Lib\Markdown;
4
5
use InvalidArgumentException;
6
use League\CommonMark\ElementRendererInterface;
7
use League\CommonMark\HtmlElement;
8
use League\CommonMark\Inline\Element\AbstractInline;
9
use League\CommonMark\Inline\Element\Link;
10
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
11
12
class ExternalLinkRenderer implements InlineRendererInterface
13
{
14
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer): HtmlElement
15
    {
16
        if (! $inline instanceof Link) {
17
            throw new InvalidArgumentException('Inline must be instance of ' . Link::class);
18
        }
19
20
        $attributes = [];
21
22
        $url = $inline->getUrl();
23
24
        if (strpos($url, '*') === 0) {
25
            $url = substr($url, 1);
26
27
            $attributes['target'] = '_blank';
28
        }
29
30
        $attributes['href'] = $url;
31
32
        return new HtmlElement(
33
            'a',
34
            $attributes,
35
            $htmlRenderer->renderInlines($inline->children())
0 ignored issues
show
Documentation introduced by
$inline->children() is of type array<integer,object<Lea...\CommonMark\Node\Node>>, but the function expects a array<integer,object<Lea...lement\AbstractInline>>.

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...
36
        );
37
    }
38
}
39