TableRowsRenderer::render()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 0
cts 15
cp 0
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the webuni/commonmark-table-extension package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Webuni\CommonMark\TableExtension;
16
17
use League\CommonMark\Block\Element\AbstractBlock;
18
use League\CommonMark\Block\Renderer\BlockRendererInterface;
19
use League\CommonMark\ElementRendererInterface;
20
use League\CommonMark\HtmlElement;
21
use League\CommonMark\Util\Xml;
22
23 View Code Duplication
class TableRowsRenderer implements BlockRendererInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26
    {
27
        if (!$block instanceof TableRows) {
28
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
29
        }
30
31
        if (!$block->hasChildren()) {
32
            return '';
33
        }
34
35
        $attrs = [];
36
        foreach ($block->getData('attributes', []) as $key => $value) {
37
            $attrs[$key] = Xml::escape($value);
38
        }
39
40
        $separator = $htmlRenderer->getOption('inner_separator', "\n");
41
42
        return new HtmlElement($block->type, $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator);
43
    }
44
}
45