Passed
Push — main ( c4d88e...057518 )
by Colin
02:18 queued 12s
created

MarkdownToXmlConverter::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Xml;
15
16
use League\CommonMark\ConverterInterface;
17
use League\CommonMark\Environment\EnvironmentInterface;
18
use League\CommonMark\Output\RenderedContentInterface;
19
use League\CommonMark\Parser\MarkdownParser;
20
use League\CommonMark\Parser\MarkdownParserInterface;
21
use League\CommonMark\Renderer\MarkdownRendererInterface;
22
23
final class MarkdownToXmlConverter implements ConverterInterface
24
{
25
    /** @psalm-readonly */
26
    private MarkdownParserInterface $parser;
27
28
    /** @psalm-readonly */
29
    private MarkdownRendererInterface $renderer;
30
31 90
    public function __construct(EnvironmentInterface $environment)
32
    {
33 90
        $this->parser   = new MarkdownParser($environment);
34 90
        $this->renderer = new XmlRenderer($environment);
35 90
    }
36
37
    /**
38
     * Converts Markdown to XML
39
     *
40
     * @throws \RuntimeException
41
     */
42 90
    public function convert(string $input): RenderedContentInterface
43
    {
44 90
        return $this->renderer->renderDocument($this->parser->parse($input));
45
    }
46
47
    /**
48
     * Converts CommonMark to HTML.
49
     *
50
     * @see MarkdownToXmlConverter::convert()
51
     *
52
     * @throws \RuntimeException
53
     */
54 2
    public function __invoke(string $input): RenderedContentInterface
55
    {
56 2
        return $this->convert($input);
57
    }
58
}
59