Passed
Pull Request — main (#1074)
by
unknown
03:19
created

TableOfContentsWrapperRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 34
ccs 14
cts 17
cp 0.8235
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getXmlAttributes() 0 3 1
A render() 0 15 2
A getXmlTagName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\TableOfContents;
15
16
use InvalidArgumentException;
17
use League\CommonMark\Extension\TableOfContents\Node\TableOfContentsWrapper;
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
24
final class TableOfContentsWrapperRenderer implements NodeRendererInterface, XmlNodeRendererInterface
25
{
26
    /**
27
     * {@inheritDoc}
28
     */
29 2
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
30
    {
31 2
        TableOfContentsWrapper::assertInstanceOf($node);
32 2
        $children = $node->children();
33 2
        if (count($children) !== 2) {
34
            throw new InvalidArgumentException(
35
                'TableOfContentsWrapper nodes should have 2 children, found ' . count($children)
36
            );
37
        }
38 2
        $attrs = $node->data->get('attributes');
39
40 2
        return new HtmlElement(
41 2
            'div',
42 2
            $attrs,
43 2
            $childRenderer->renderNodes($children)
44 2
        );
45
    }
46
47 2
    public function getXmlTagName(Node $node): string
48
    {
49 2
        return 'table_of_contents_wrapper';
50
    }
51
52
    /**
53
     * @return array<string, scalar>
54
     */
55 2
    public function getXmlAttributes(Node $node): array
56
    {
57 2
        return [];
58
    }
59
}
60