Completed
Push — master ( 7a0a03...73b89e )
by Colin
02:28
created

HtmlBlockRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 28
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 8 2
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\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
use League\CommonMark\Util\HtmlFilter;
25
26
final class HtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
27
{
28
    /**
29
     * @var ConfigurationInterface
30
     */
31
    protected $config;
32
33
    /*
34
     * @param HtmlBlock             $block
35
     * @param NodeRendererInterface $htmlRenderer
36
     * @param bool                  $inTightList
37
     *
38
     * @return string
39
     */
40 183
    public function render(AbstractBlock $block, NodeRendererInterface $htmlRenderer, bool $inTightList = false)
41
    {
42 183
        if (!($block instanceof HtmlBlock)) {
43 3
            throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
44
        }
45
46 180
        return HtmlFilter::filter($block->getStringContent(), $this->config->get('html_input', HtmlFilter::ALLOW));
47
    }
48
49 2505
    public function setConfiguration(ConfigurationInterface $configuration): void
50
    {
51 2505
        $this->config = $configuration;
52 2505
    }
53
}
54