TableRowRenderer::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 15
loc 15
ccs 0
cts 12
cp 0
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 12
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 TableRowRenderer 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 TableRow) {
28
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
29
        }
30
31
        $attrs = [];
32
        foreach ($block->getData('attributes', []) as $key => $value) {
33
            $attrs[$key] = Xml::escape($value);
34
        }
35
36
        $separator = $htmlRenderer->getOption('inner_separator', "\n");
37
38
        return new HtmlElement('tr', $attrs, $separator.$htmlRenderer->renderBlocks($block->children()).$separator);
39
    }
40
}
41