Completed
Push — master ( 1c51ea...167531 )
by Colin
8s
created

HtmlInlineRenderer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B render() 0 21 5
A setConfiguration() 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\Inline\Renderer;
16
17
use League\CommonMark\ElementRendererInterface;
18
use League\CommonMark\Environment;
19
use League\CommonMark\Inline\Element\AbstractInline;
20
use League\CommonMark\Inline\Element\HtmlInline;
21
use League\CommonMark\Util\Configuration;
22
use League\CommonMark\Util\ConfigurationAwareInterface;
23
24
class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface
25
{
26
    /**
27
     * @var Configuration
28
     */
29
    protected $config;
30
31
    /**
32
     * @param HtmlInline               $inline
33
     * @param ElementRendererInterface $htmlRenderer
34
     *
35
     * @return string
36
     */
37 87
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
38
    {
39 87
        if (!($inline instanceof HtmlInline)) {
40 3
            throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
41
        }
42
43
        // Kept for BC reasons
44 84
        if ($this->config->getConfig('safe') === true) {
45 3
            return '';
46
        }
47
48 81
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_STRIP) {
49 3
            return '';
50
        }
51
52 78
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_ESCAPE) {
53 3
            return htmlspecialchars($inline->getContent(), ENT_NOQUOTES);
54
        }
55
56 75
        return $inline->getContent();
57
    }
58
59
    /**
60
     * @param Configuration $configuration
61
     */
62 1899
    public function setConfiguration(Configuration $configuration)
63
    {
64 1899
        $this->config = $configuration;
65 1899
    }
66
}
67