HtmlBlockRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
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 39
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\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\EnvironmentInterface;
21
use League\CommonMark\Util\ConfigurationAwareInterface;
22
use League\CommonMark\Util\ConfigurationInterface;
23
24
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
25
{
26
    /**
27
     * @var ConfigurationInterface
28
     */
29
    protected $config;
30
31
    /**
32
     * @param HtmlBlock                $block
33
     * @param ElementRendererInterface $htmlRenderer
34
     * @param bool                     $inTightList
35
     *
36
     * @return string
37
     */
38 171
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
39
    {
40 171
        if (!($block instanceof HtmlBlock)) {
41 3
            throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
42
        }
43
44 168
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) {
45 6
            return '';
46
        }
47
48 162
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) {
49 6
            return \htmlspecialchars($block->getStringContent(), \ENT_NOQUOTES);
50
        }
51
52 156
        return $block->getStringContent();
53
    }
54
55
    /**
56
     * @param ConfigurationInterface $configuration
57
     */
58 2079
    public function setConfiguration(ConfigurationInterface $configuration)
59
    {
60 2079
        $this->config = $configuration;
61 2079
    }
62
}
63