Completed
Push — feature/resolve-parent-class ( 1a8a55...248da8 )
by Colin
35:17 queued 33:54
created

Converter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0185
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark;
13
14
/**
15
 * Converts CommonMark-compatible Markdown to HTML.
16
 *
17
 * @deprecated This class is deprecated since league/commonmark 1.4, use CommonMarkConverter instead.
18
 */
19
class Converter implements MarkdownConverterInterface
20
{
21
    /**
22
     * The document parser instance.
23
     *
24
     * @var DocParserInterface
25
     */
26
    protected $docParser;
27
28
    /**
29
     * The html renderer instance.
30
     *
31
     * @var ElementRendererInterface
32
     */
33
    protected $htmlRenderer;
34
35
    /**
36
     * Create a new commonmark converter instance.
37
     *
38
     * @param DocParserInterface       $docParser
39
     * @param ElementRendererInterface $htmlRenderer
40
     */
41 2361
    public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer)
42
    {
43 2361
        if (!($this instanceof CommonMarkConverter)) {
44
            @trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, CommonMarkConverter::class), E_USER_DEPRECATED);
45
        }
46
47 2361
        $this->docParser = $docParser;
48 2361
        $this->htmlRenderer = $htmlRenderer;
49 2361
    }
50
51
    /**
52
     * Converts CommonMark to HTML.
53
     *
54
     * @param string $commonMark
55
     *
56
     * @throws \RuntimeException
57
     *
58
     * @return string
59
     *
60
     * @api
61
     */
62 2352
    public function convertToHtml(string $commonMark): string
63
    {
64 2352
        $documentAST = $this->docParser->parse($commonMark);
65
66 2346
        return $this->htmlRenderer->renderBlock($documentAST);
67
    }
68
69
    /**
70
     * Converts CommonMark to HTML.
71
     *
72
     * @see Converter::convertToHtml
73
     *
74
     * @param string $commonMark
75
     *
76
     * @throws \RuntimeException
77
     *
78
     * @return string
79
     */
80 3
    public function __invoke(string $commonMark): string
81
    {
82 3
        return $this->convertToHtml($commonMark);
83
    }
84
}
85