Passed
Push — latest ( 3af091...d64e46 )
by Colin
03:49 queued 01:39
created

DescriptionListRenderer::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\DescriptionList\Renderer;
15
16
use League\CommonMark\Extension\DescriptionList\Node\DescriptionList;
17
use League\CommonMark\Node\Node;
18
use League\CommonMark\Renderer\ChildNodeRendererInterface;
19
use League\CommonMark\Renderer\NodeRendererInterface;
20
use League\CommonMark\Util\HtmlElement;
21
22
final class DescriptionListRenderer implements NodeRendererInterface
23
{
24
    /**
25
     * @param DescriptionList $node
26
     *
27
     * {@inheritdoc}
28
     *
29
     * @psalm-suppress MoreSpecificImplementedParamType
30
     */
31 39
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): HtmlElement
32
    {
33 39
        if (! ($node instanceof DescriptionList)) {
34 3
            throw new \InvalidArgumentException('Incompatible node type: ' . \get_class($node));
35
        }
36
37 36
        $separator = $childRenderer->getBlockSeparator();
38
39 36
        return new HtmlElement('dl', [], $separator . $childRenderer->renderNodes($node->children()) . $separator);
40
    }
41
}
42