Passed
Push — latest ( d59ff4...6fb795 )
by Colin
08:12
created

FootnoteRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 17
ccs 10
cts 11
cp 0.9091
rs 9.9
c 1
b 0
f 0
cc 2
nc 2
nop 2
crap 2.003
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\Configuration\ConfigurationAwareInterface;
18
use League\CommonMark\Configuration\ConfigurationInterface;
19
use League\CommonMark\Extension\Footnote\Node\Footnote;
20
use League\CommonMark\Node\Node;
21
use League\CommonMark\Renderer\ChildNodeRendererInterface;
22
use League\CommonMark\Renderer\NodeRendererInterface;
23
use League\CommonMark\Util\HtmlElement;
24
25
final class FootnoteRenderer implements NodeRendererInterface, ConfigurationAwareInterface
26
{
27
    /** @var ConfigurationInterface */
28
    private $config;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 48
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
34
    {
35 48
        if (! ($node instanceof Footnote)) {
36
            throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node));
37
        }
38
39 48
        $attrs = $node->getData('attributes', []);
40
41 48
        $attrs['class'] = $attrs['class'] ?? $this->config->get('footnote/footnote_class', 'footnote');
42 48
        $attrs['id']    = $this->config->get('footnote/footnote_id_prefix', 'fn:') . \mb_strtolower($node->getReference()->getLabel());
43 48
        $attrs['role']  = 'doc-endnote';
44
45 48
        return new HtmlElement(
46 48
            'li',
47
            $attrs,
48 48
            $childRenderer->renderNodes($node->children()),
49 48
            true
50
        );
51
    }
52
53 54
    public function setConfiguration(ConfigurationInterface $configuration): void
54
    {
55 54
        $this->config = $configuration;
56 54
    }
57
}
58