Passed
Push — main ( 057518...00c1b7 )
by Colin
02:29 queued 26s
created

HtmlDecorator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
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\Renderer;
15
16
use League\CommonMark\Node\Node;
17
use League\CommonMark\Util\HtmlElement;
18
19
final class HtmlDecorator implements NodeRendererInterface
20
{
21
    private NodeRendererInterface $inner;
22
    private string $tag;
23
    /** @var array<string, string|string[]|bool> */
24
    private array $attributes;
25
    private bool $selfClosing;
26
27
    /**
28
     * @param array<string, string|string[]|bool> $attributes
29
     */
30 4
    public function __construct(NodeRendererInterface $inner, string $tag, array $attributes = [], bool $selfClosing = false)
31
    {
32 4
        $this->inner       = $inner;
33 4
        $this->tag         = $tag;
34 4
        $this->attributes  = $attributes;
35 4
        $this->selfClosing = $selfClosing;
36 4
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 4
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
42
    {
43 4
        return new HtmlElement($this->tag, $this->attributes, $this->inner->render($node, $childRenderer), $this->selfClosing);
44
    }
45
}
46