Completed
Push — master ( 83739a...a13ee4 )
by Colin
14s queued 11s
created

Converter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 62
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A convertToHtml() 0 6 1
A __invoke() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark;
16
17
/**
18
 * Converts CommonMark-compatible Markdown to HTML.
19
 */
20
class Converter implements ConverterInterface
21
{
22
    /**
23
     * The document parser instance.
24
     *
25
     * @var \League\CommonMark\DocParserInterface
26
     */
27
    protected $docParser;
28
29
    /**
30
     * The html renderer instance.
31
     *
32
     * @var \League\CommonMark\ElementRendererInterface
33
     */
34
    protected $htmlRenderer;
35
36
    /**
37
     * Create a new commonmark converter instance.
38
     *
39
     * @param DocParserInterface       $docParser
40
     * @param ElementRendererInterface $htmlRenderer
41
     */
42 2334
    public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer)
43
    {
44 2334
        $this->docParser = $docParser;
45 2334
        $this->htmlRenderer = $htmlRenderer;
46 2334
    }
47
48
    /**
49
     * Converts CommonMark to HTML.
50
     *
51
     * @param string $commonMark
52
     *
53
     * @throws \RuntimeException
54
     *
55
     * @return string
56
     *
57
     * @api
58
     */
59 2325
    public function convertToHtml(string $commonMark): string
60
    {
61 2325
        $documentAST = $this->docParser->parse($commonMark);
62
63 2322
        return $this->htmlRenderer->renderBlock($documentAST);
64
    }
65
66
    /**
67
     * Converts CommonMark to HTML.
68
     *
69
     * @see Converter::convertToHtml
70
     *
71
     * @param string $commonMark
72
     *
73
     * @throws \RuntimeException
74
     *
75
     * @return string
76
     */
77 3
    public function __invoke(string $commonMark): string
78
    {
79 3
        return $this->convertToHtml($commonMark);
80
    }
81
}
82