Completed
Push — 2.0 ( a89474...4b9bf2 )
by Colin
02:19 queued 02:16
created

TableSectionRenderer::getXmlTagName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the league/commonmark package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
10
 * (c) Colin O'Dell <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace League\CommonMark\Extension\Table;
17
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 TableSectionRenderer implements NodeRendererInterface, XmlNodeRendererInterface
25
{
26
    /**
27
     * @param TableSection $node
28
     *
29
     * {@inheritDoc}
30
     *
31
     * @psalm-suppress MoreSpecificImplementedParamType
32
     */
33 36
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
34
    {
35 36
        TableSection::assertInstanceOf($node);
36
37 33
        if (! $node->hasChildren()) {
38 3
            return '';
39
        }
40
41 30
        $attrs = $node->data->get('attributes');
42
43 30
        $separator = $childRenderer->getInnerSeparator();
44
45 30
        $tag = $node->getType() === TableSection::TYPE_HEAD ? 'thead' : 'tbody';
46
47 30
        return new HtmlElement($tag, $attrs, $separator . $childRenderer->renderNodes($node->children()) . $separator);
48
    }
49
50 3
    public function getXmlTagName(Node $node): string
51
    {
52 3
        return 'table_section';
53
    }
54
55
    /**
56
     * @param TableSection $node
57
     *
58
     * @return array<string, scalar>
59
     *
60
     * @psalm-suppress MoreSpecificImplementedParamType
61
     */
62 3
    public function getXmlAttributes(Node $node): array
63
    {
64 3
        TableSection::assertInstanceOf($node);
65
66
        return [
67 3
            'type' => $node->getType(),
68
        ];
69
    }
70
}
71