Completed
Push — master ( b4bf5d...de0487 )
by Colin
15s queued 11s
created

TableSectionRenderer::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 8
cp 0.75
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3.1406
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
23
final class TableSectionRenderer implements BlockRendererInterface
24
{
25 34
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26
    {
27 34
        if (!$block instanceof TableSection) {
28
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
29
        }
30
31 34
        if (!$block->hasChildren()) {
32
            return '';
33
        }
34
35 34
        $attrs = $block->getData('attributes', []);
36
37 34
        $separator = $htmlRenderer->getOption('inner_separator', "\n");
38
39 34
        return new HtmlElement($block->type, $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator);
40
    }
41
}
42