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

FootnoteContainerRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 28
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 17 3
A setConfiguration() 0 4 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\Block\Element\AbstractBlock;
18
use League\CommonMark\Block\Renderer\BlockRendererInterface;
19
use League\CommonMark\ElementRendererInterface;
20
use League\CommonMark\Extension\Footnote\Node\FootnoteContainer;
21
use League\CommonMark\HtmlElement;
22
use League\CommonMark\Util\ConfigurationAwareInterface;
23
use League\CommonMark\Util\ConfigurationInterface;
24
25
final class FootnoteContainerRenderer implements BlockRendererInterface, ConfigurationAwareInterface
26
{
27
    /** @var ConfigurationInterface */
28
    private $config;
29
30 48
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
31
    {
32 48
        if (!($block instanceof FootnoteContainer)) {
33
            throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
34
        }
35
36 48
        $attrs = $block->getData('attributes', []);
37 48
        $attrs['class'] = $attrs['class'] ?? $this->config->get('footnote/container_class', 'footnotes');
38 48
        $attrs['role'] = 'doc-endnotes';
39
40 48
        $contents = new HtmlElement('ol', [], $htmlRenderer->renderBlocks($block->children()));
41 48
        if ($this->config->get('footnote/container_add_hr', true)) {
42 45
            $contents = [new HtmlElement('hr', [], null, true), $contents];
43
        }
44
45 48
        return new HtmlElement('div', $attrs, $contents);
46
    }
47
48 54
    public function setConfiguration(ConfigurationInterface $configuration)
49
    {
50 54
        $this->config = $configuration;
51 54
    }
52
}
53