Passed
Push — dependabot/github_actions/ride... ( 68a0b3 )
by
unknown
03:10
created

MarkdownConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 13
dl 0
loc 68
ccs 11
cts 14
cp 0.7856
rs 10
c 3
b 0
f 1
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getEnvironment() 0 3 1
A convertToHtml() 0 5 1
A __invoke() 0 3 1
A convert() 0 5 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;
15
16
use League\CommonMark\Environment\EnvironmentInterface;
17
use League\CommonMark\Output\RenderedContentInterface;
18
use League\CommonMark\Parser\MarkdownParser;
19
use League\CommonMark\Parser\MarkdownParserInterface;
20
use League\CommonMark\Renderer\HtmlRenderer;
21
use League\CommonMark\Renderer\MarkdownRendererInterface;
22
23
class MarkdownConverter implements ConverterInterface, MarkdownConverterInterface
0 ignored issues
show
Deprecated Code introduced by
The interface League\CommonMark\MarkdownConverterInterface has been deprecated: since 2.2; use {@link ConverterInterface} instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

23
class MarkdownConverter implements ConverterInterface, /** @scrutinizer ignore-deprecated */ MarkdownConverterInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
24
{
25
    /** @psalm-readonly */
26
    protected EnvironmentInterface $environment;
27
28
    /** @psalm-readonly */
29
    protected MarkdownParserInterface $markdownParser;
30
31
    /** @psalm-readonly */
32
    protected MarkdownRendererInterface $htmlRenderer;
33
34 2048
    public function __construct(EnvironmentInterface $environment)
35
    {
36 2048
        $this->environment = $environment;
37
38 2048
        $this->markdownParser = new MarkdownParser($environment);
39 2048
        $this->htmlRenderer   = new HtmlRenderer($environment);
40
    }
41
42 2
    public function getEnvironment(): EnvironmentInterface
43
    {
44 2
        return $this->environment;
45
    }
46
47
    /**
48
     * Converts Markdown to HTML.
49
     *
50
     * @param string $input The Markdown to convert
51
     *
52
     * @return RenderedContentInterface Rendered HTML
53
     *
54
     * @throws \RuntimeException
55
     */
56 2034
    public function convert(string $input): RenderedContentInterface
57
    {
58 2034
        $documentAST = $this->markdownParser->parse($input);
59
60 2018
        return $this->htmlRenderer->renderDocument($documentAST);
61
    }
62
63
    /**
64
     * Converts Markdown to HTML.
65
     *
66
     * @deprecated since 2.2; use {@link convert()} instead
67
     *
68
     * @param string $markdown The Markdown to convert
69
     *
70
     * @return RenderedContentInterface Rendered HTML
71
     *
72
     * @throws \RuntimeException
73
     */
74
    public function convertToHtml(string $markdown): RenderedContentInterface
75
    {
76
        \trigger_deprecation('league/commonmark', '2.2.0', 'Calling "convertToHtml()" on a %s class is deprecated, use "convert()" instead.', self::class);
77
78
        return $this->convert($markdown);
79
    }
80
81
    /**
82
     * Converts CommonMark to HTML.
83
     *
84
     * @see MarkdownConverter::convert()
85
     *
86
     * @throws \RuntimeException
87
     */
88 4
    public function __invoke(string $markdown): RenderedContentInterface
89
    {
90 4
        return $this->convert($markdown);
91
    }
92
}
93