Completed
Push — master ( 34c45b...b3198b )
by Colin
24:19 queued 24:15
created

Converter   A

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
21
{
22
    /**
23
     * The document parser instance.
24
     *
25
     * @var \League\CommonMark\DocParser
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 DocParser                $docParser
40
     * @param ElementRendererInterface $htmlRenderer
41
     */
42 1863
    public function __construct(DocParser $docParser, ElementRendererInterface $htmlRenderer)
43
    {
44 1863
        $this->docParser = $docParser;
45 1863
        $this->htmlRenderer = $htmlRenderer;
46 1863
    }
47
48
    /**
49
     * Converts CommonMark to HTML.
50
     *
51
     * @param string $commonMark
52
     *
53
     * @return string
54
     *
55
     * @api
56
     */
57 1854
    public function convertToHtml($commonMark)
58
    {
59 1854
        $documentAST = $this->docParser->parse($commonMark);
60
61 1854
        return $this->htmlRenderer->renderBlock($documentAST);
62
    }
63
64
    /**
65
     * Converts CommonMark to HTML.
66
     *
67
     * @see Converter::convertToHtml
68
     *
69
     * @param $commonMark
70
     *
71
     * @return string
72
     */
73 3
    public function __invoke($commonMark)
74
    {
75 3
        return $this->convertToHtml($commonMark);
76
    }
77
}
78