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

HtmlBlockRenderer::render()   B

Complexity

Conditions 5
Paths 5

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 21
Code Lines 10

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 8.7624
cc 5
eloc 10
nc 5
nop 3
crap 5
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 162
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
39
    {
40 162
        if (!($block instanceof HtmlBlock)) {
41 3
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
42
        }
43
44
        // Kept for BC reasons
45 159
        if ($this->config->getConfig('safe') === true) {
46 6
            return '';
47
        }
48
49 153
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_STRIP) {
50 6
            return '';
51
        }
52
53 147
        if ($this->config->getConfig('html_input') === Environment::HTML_INPUT_ESCAPE) {
54 6
            return htmlspecialchars($block->getStringContent(), ENT_NOQUOTES);
55
        }
56
57 141
        return $block->getStringContent();
58
    }
59
60
    /**
61
     * @param Configuration $configuration
62
     */
63 1899
    public function setConfiguration(Configuration $configuration)
64
    {
65 1899
        $this->config = $configuration;
66 1899
    }
67
}
68