TableCellRenderer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 13 3
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
23
final class TableCellRenderer implements NodeRendererInterface
24
{
25
    /**
26
     * @param TableCell $node
27
     *
28
     * {@inheritdoc}
29
     *
30
     * @psalm-suppress MoreSpecificImplementedParamType
31
     */
32 87
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
33
    {
34 87
        if (! $node instanceof TableCell) {
35 3
            throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node));
36
        }
37
38 84
        $attrs = $node->data->get('attributes');
39
40 84
        if ($node->getAlign() !== null) {
41 18
            $attrs['align'] = $node->getAlign();
42
        }
43
44 84
        return new HtmlElement($node->getType(), $attrs, $childRenderer->renderNodes($node->children()));
45
    }
46
}
47