HtmlInlineRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 38
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 16 4
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\EnvironmentInterface;
19
use League\CommonMark\Inline\Element\AbstractInline;
20
use League\CommonMark\Inline\Element\HtmlInline;
21
use League\CommonMark\Util\ConfigurationAwareInterface;
22
use League\CommonMark\Util\ConfigurationInterface;
23
24
final class HtmlInlineRenderer implements InlineRendererInterface, ConfigurationAwareInterface
25
{
26
    /**
27
     * @var ConfigurationInterface
28
     */
29
    protected $config;
30
31
    /**
32
     * @param HtmlInline               $inline
33
     * @param ElementRendererInterface $htmlRenderer
34
     *
35
     * @return string
36
     */
37 96
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
38
    {
39 96
        if (!($inline instanceof HtmlInline)) {
40 3
            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
41
        }
42
43 93
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) {
44 3
            return '';
45
        }
46
47 90
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) {
48 3
            return htmlspecialchars($inline->getContent(), ENT_NOQUOTES);
49
        }
50
51 87
        return $inline->getContent();
52
    }
53
54
    /**
55
     * @param ConfigurationInterface $configuration
56
     */
57 2079
    public function setConfiguration(ConfigurationInterface $configuration)
58
    {
59 2079
        $this->config = $configuration;
60 2079
    }
61
}
62