Passed
Push — dependabot/github_actions/ride... ( 115027 )
by
unknown
02:30
created

DocumentRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 7 2
A getXmlTagName() 0 3 1
A getXmlAttributes() 0 4 1
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
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace League\CommonMark\Renderer\Block;
18
19
use League\CommonMark\Node\Block\Document;
20
use League\CommonMark\Node\Node;
21
use League\CommonMark\Renderer\ChildNodeRendererInterface;
22
use League\CommonMark\Renderer\NodeRendererInterface;
23
use League\CommonMark\Xml\XmlNodeRendererInterface;
24
25
final class DocumentRenderer implements NodeRendererInterface, XmlNodeRendererInterface
26
{
27
    /**
28
     * @param Document $node
29
     *
30
     * {@inheritDoc}
31
     *
32
     * @psalm-suppress MoreSpecificImplementedParamType
33
     */
34 2068
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): string
35
    {
36 2068
        Document::assertInstanceOf($node);
37
38 2066
        $wholeDoc = $childRenderer->renderNodes($node->children());
39
40 2066
        return $wholeDoc === '' ? '' : $wholeDoc . "\n";
41
    }
42
43 98
    public function getXmlTagName(Node $node): string
44
    {
45 98
        return 'document';
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 98
    public function getXmlAttributes(Node $node): array
52
    {
53
        return [
54 98
            'xmlns' => 'http://commonmark.org/xml/1.0',
55
        ];
56
    }
57
}
58