TableSectionRenderer::getXmlAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 60
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
34
    {
35 60
        TableSection::assertInstanceOf($node);
36
37 58
        if (! $node->hasChildren()) {
38 2
            return '';
39
        }
40
41 56
        $attrs = $node->data->get('attributes');
42
43 56
        $separator = $childRenderer->getInnerSeparator();
44
45 56
        $tag = $node->getType() === TableSection::TYPE_HEAD ? 'thead' : 'tbody';
46
47 56
        return new HtmlElement($tag, $attrs, $separator . $childRenderer->renderNodes($node->children()) . $separator);
48
    }
49
50 2
    public function getXmlTagName(Node $node): string
51
    {
52 2
        return 'table_section';
53
    }
54
55
    /**
56
     * @param TableSection $node
57
     *
58
     * @return array<string, scalar>
59
     *
60
     * @psalm-suppress MoreSpecificImplementedParamType
61
     */
62 2
    public function getXmlAttributes(Node $node): array
63
    {
64 2
        TableSection::assertInstanceOf($node);
65
66 2
        return [
67 2
            'type' => $node->getType(),
68 2
        ];
69
    }
70
}
71