Passed
Push — main ( 989696...2152d5 )
by Colin
05:14 queued 02:09
created

FootnoteContainerRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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\Extension\Footnote\Node\FootnoteContainer;
18
use League\CommonMark\Node\Node;
19
use League\CommonMark\Renderer\ChildNodeRendererInterface;
20
use League\CommonMark\Renderer\NodeRendererInterface;
21
use League\CommonMark\Util\HtmlElement;
22
use League\CommonMark\Xml\XmlNodeRendererInterface;
23
use League\Config\ConfigurationAwareInterface;
24
use League\Config\ConfigurationInterface;
25
26
final class FootnoteContainerRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface
27
{
28
    /** @var ConfigurationInterface */
29
    private $config;
30
31
    /**
32
     * @param FootnoteContainer $node
33
     *
34
     * {@inheritDoc}
35
     *
36
     * @psalm-suppress MoreSpecificImplementedParamType
37
     */
38 108
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
39
    {
40 108
        FootnoteContainer::assertInstanceOf($node);
41
42 108
        $attrs = $node->data->getData('attributes');
43
44 108
        $attrs->append('class', $this->config->get('footnote/container_class'));
45 108
        $attrs->set('role', 'doc-endnotes');
46
47 108
        $contents = new HtmlElement('ol', [], $childRenderer->renderNodes($node->children()));
48 108
        if ($this->config->get('footnote/container_add_hr')) {
49 99
            $contents = [new HtmlElement('hr', [], null, true), $contents];
50
        }
51
52 108
        return new HtmlElement('div', $attrs->export(), $contents);
53
    }
54
55 147
    public function setConfiguration(ConfigurationInterface $configuration): void
56
    {
57 147
        $this->config = $configuration;
58 147
    }
59
60 27
    public function getXmlTagName(Node $node): string
61
    {
62 27
        return 'footnote_container';
63
    }
64
65
    /**
66
     * @return array<string, scalar>
67
     */
68 27
    public function getXmlAttributes(Node $node): array
69
    {
70 27
        return [];
71
    }
72
}
73