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

ExternalLinkRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 24 3
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