HtmlInlineRenderer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A 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 90
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
38
    {
39 90
        if (!($inline instanceof HtmlInline)) {
40 3
            throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
41
        }
42
43
        // Kept for BC reasons
44 87
        if ($this->config->getConfig('safe') === true) {
45 3
            return '';
46
        }
47
48 84
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_STRIP) {
49 3
            return '';
50
        }
51
52 81
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_ESCAPE) {
53 3
            return htmlspecialchars($inline->getContent(), ENT_NOQUOTES);
54
        }
55
56 78
        return $inline->getContent();
57
    }
58
59
    /**
60
     * @param Configuration $configuration
61
     */
62 1959
    public function setConfiguration(Configuration $configuration)
63
    {
64 1959
        $this->config = $configuration;
65 1959
    }
66
}
67