Completed
Push — master ( 9eb60a...7a0a03 )
by Colin
36:39 queued 35:14
created

HtmlBlockRenderer::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 4
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\Extension\CommonMark\Renderer\Block;
16
17
use League\CommonMark\Configuration\ConfigurationAwareInterface;
18
use League\CommonMark\Configuration\ConfigurationInterface;
19
use League\CommonMark\Environment\EnvironmentInterface;
20
use League\CommonMark\Extension\CommonMark\Node\Block\HtmlBlock;
21
use League\CommonMark\Node\Block\AbstractBlock;
22
use League\CommonMark\Renderer\Block\BlockRendererInterface;
23
use League\CommonMark\Renderer\NodeRendererInterface;
24
25
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
26
{
27
    /**
28
     * @var ConfigurationInterface
29
     */
30
    protected $config;
31
32
     * @param HtmlBlock             $block
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '*', expecting T_FUNCTION or T_CONST
Loading history...
33
     * @param NodeRendererInterface $htmlRenderer
34
     * @param bool                  $inTightList
35
     *
36
     * @return string
37
     */
38
    public function render(AbstractBlock $block, NodeRendererInterface $htmlRenderer, bool $inTightList = false)
39
    {
40
        if (!($block instanceof HtmlBlock)) {
41
            throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
42
        }
43
44
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_STRIP) {
45
            return '';
46
        }
47
48
        if ($this->config->get('html_input') === EnvironmentInterface::HTML_INPUT_ESCAPE) {
49
            return \htmlspecialchars($block->getStringContent(), \ENT_NOQUOTES);
50
        }
51
52
        return $block->getStringContent();
53
    }
54
55
    public function setConfiguration(ConfigurationInterface $configuration): void
56
    {
57
        $this->config = $configuration;
58
    }
59
}
60