Completed
Push — 1.5 ( f40f61...09e907 )
by Colin
02:28
created

FootnoteBackrefRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 9
cp 0.8889
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0054
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 * (c) Rezo Zero / Ambroise Maupate
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace League\CommonMark\Extension\Footnote\Renderer;
16
17
use League\CommonMark\ElementRendererInterface;
18
use League\CommonMark\Extension\Footnote\Node\FootnoteBackref;
19
use League\CommonMark\HtmlElement;
20
use League\CommonMark\Inline\Element\AbstractInline;
21
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
22
use League\CommonMark\Util\ConfigurationAwareInterface;
23
use League\CommonMark\Util\ConfigurationInterface;
24
25
final class FootnoteBackrefRenderer implements InlineRendererInterface, ConfigurationAwareInterface
26
{
27
    /** @var ConfigurationInterface */
28
    private $config;
29
30 45
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
31
    {
32 45
        if (!($inline instanceof FootnoteBackref)) {
33
            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
34
        }
35
36 45
        $attrs = $inline->getData('attributes', []);
37 45
        $attrs['class'] = $attrs['class'] ?? $this->config->get('footnote/backref_class', 'footnote-backref');
38 45
        $attrs['rev'] = 'footnote';
39 45
        $attrs['href'] = \mb_strtolower($inline->getReference()->getDestination());
40 45
        $attrs['role'] = 'doc-backlink';
41
42 45
        return '&nbsp;' . new HtmlElement('a', $attrs, '&#8617;', true);
43
    }
44
45 51
    public function setConfiguration(ConfigurationInterface $configuration)
46
    {
47 51
        $this->config = $configuration;
48 51
    }
49
}
50