Completed
Push — master ( 4bb680...8b36bf )
by Colin
03:09
created

TableSectionRenderer::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 7
cts 10
cp 0.7
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 4.432
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the league/commonmark-ext-table 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\Ext\Table;
17
18
use League\CommonMark\Block\Element\AbstractBlock;
19
use League\CommonMark\Block\Renderer\BlockRendererInterface;
20
use League\CommonMark\ElementRendererInterface;
21
use League\CommonMark\HtmlElement;
22
use League\CommonMark\Util\Xml;
23
24
final class TableSectionRenderer implements BlockRendererInterface
25
{
26 34
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
27
    {
28 34
        if (!$block instanceof TableSection) {
29
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
30
        }
31
32 34
        if (!$block->hasChildren()) {
33
            return '';
34
        }
35
36 34
        $attrs = [];
37 34
        foreach ($block->getData('attributes', []) as $key => $value) {
38
            $attrs[$key] = Xml::escape($value);
39
        }
40
41 34
        $separator = $htmlRenderer->getOption('inner_separator', "\n");
42
43 34
        return new HtmlElement($block->type, $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator);
44
    }
45
}
46