FootnoteRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 52
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getXmlTagName() 0 3 1
A setConfiguration() 0 3 1
A render() 0 15 1
A getXmlAttributes() 0 6 1
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\Footnote;
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 FootnoteRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface
27
{
28
    private ConfigurationInterface $config;
29
30
    /**
31
     * @param Footnote $node
32
     *
33
     * {@inheritDoc}
34
     *
35
     * @psalm-suppress MoreSpecificImplementedParamType
36
     */
37 76
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable
38
    {
39 76
        Footnote::assertInstanceOf($node);
40
41 76
        $attrs = $node->data->getData('attributes');
42
43 76
        $attrs->append('class', $this->config->get('footnote/footnote_class'));
44 76
        $attrs->set('id', $this->config->get('footnote/footnote_id_prefix') . \mb_strtolower($node->getReference()->getLabel(), 'UTF-8'));
45 76
        $attrs->set('role', 'doc-endnote');
46
47 76
        return new HtmlElement(
48 76
            'li',
49 76
            $attrs->export(),
50 76
            $childRenderer->renderNodes($node->children()),
51 76
            true
52 76
        );
53
    }
54
55 102
    public function setConfiguration(ConfigurationInterface $configuration): void
56
    {
57 102
        $this->config = $configuration;
58
    }
59
60 18
    public function getXmlTagName(Node $node): string
61
    {
62 18
        return 'footnote';
63
    }
64
65
    /**
66
     * @param Footnote $node
67
     *
68
     * @return array<string, scalar>
69
     *
70
     * @psalm-suppress MoreSpecificImplementedParamType
71
     */
72 18
    public function getXmlAttributes(Node $node): array
73
    {
74 18
        Footnote::assertInstanceOf($node);
75
76 18
        return [
77 18
            'reference' => $node->getReference()->getLabel(),
78 18
        ];
79
    }
80
}
81