HtmlBlockRenderer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
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 44
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\Block\Renderer;
16
17
use League\CommonMark\Block\Element\AbstractBlock;
18
use League\CommonMark\Block\Element\HtmlBlock;
19
use League\CommonMark\ElementRendererInterface;
20
use League\CommonMark\Environment;
21
use League\CommonMark\Util\Configuration;
22
use League\CommonMark\Util\ConfigurationAwareInterface;
23
24
class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
25
{
26
    /**
27
     * @var Configuration
28
     */
29
    protected $config;
30
31
    /**
32
     * @param HtmlBlock                $block
33
     * @param ElementRendererInterface $htmlRenderer
34
     * @param bool                     $inTightList
35
     *
36
     * @return string
37
     */
38 177
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
39
    {
40 177
        if (!($block instanceof HtmlBlock)) {
41 3
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
42
        }
43
44
        // Kept for BC reasons
45 174
        if ($this->config->getConfig('safe') === true) {
46 6
            return '';
47
        }
48
49 168
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_STRIP) {
50 6
            return '';
51
        }
52
53 162
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_ESCAPE) {
54 6
            return htmlspecialchars($block->getStringContent(), ENT_NOQUOTES);
55
        }
56
57 156
        return $block->getStringContent();
58
    }
59
60
    /**
61
     * @param Configuration $configuration
62
     */
63 1959
    public function setConfiguration(Configuration $configuration)
64
    {
65 1959
        $this->config = $configuration;
66 1959
    }
67
}
68