FootnoteRefRenderer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 18
dl 0
loc 38
ccs 17
cts 18
cp 0.9444
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 24 2
A setConfiguration() 0 3 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\FootnoteRef;
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\Config\ConfigurationAwareInterface;
23
use League\Config\ConfigurationInterface;
24
25
final class FootnoteRefRenderer implements NodeRendererInterface, ConfigurationAwareInterface
26
{
27
    /** @var ConfigurationInterface */
28
    private $config;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 108
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
34
    {
35 108
        if (! ($node instanceof FootnoteRef)) {
36
            throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node));
37
        }
38
39 108
        $attrs = $node->data->getData('attributes');
40 108
        $attrs->append('class', $this->config->get('footnote/ref_class'));
41 108
        $attrs->set('href', \mb_strtolower($node->getReference()->getDestination()));
42 108
        $attrs->set('role', 'doc-noteref');
43
44 108
        $idPrefix = $this->config->get('footnote/ref_id_prefix');
45
46 108
        return new HtmlElement(
47 108
            'sup',
48
            [
49 108
                'id' => $idPrefix . \mb_strtolower($node->getReference()->getLabel()),
50
            ],
51 108
            new HtmlElement(
52 108
                'a',
53 108
                $attrs->export(),
54 108
                $node->getReference()->getTitle()
55
            ),
56 108
            true
57
        );
58
    }
59
60 117
    public function setConfiguration(ConfigurationInterface $configuration): void
61
    {
62 117
        $this->config = $configuration;
63 117
    }
64
}
65