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

MarkdownToXmlConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 3 1
A convert() 0 3 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
 * 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