Completed
Push — master ( 83739a...a13ee4 )
by Colin
14s queued 11s
created

DisallowedRawHtmlBlockRenderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 34
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 11 2
A setConfiguration() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark\Extension\DisallowedRawHtml;
13
14
use League\CommonMark\Block\Element\AbstractBlock;
15
use League\CommonMark\Block\Renderer\BlockRendererInterface;
16
use League\CommonMark\ElementRendererInterface;
17
use League\CommonMark\Util\ConfigurationAwareInterface;
18
use League\CommonMark\Util\ConfigurationInterface;
19
20
final class DisallowedRawHtmlBlockRenderer implements BlockRendererInterface, ConfigurationAwareInterface
21
{
22
    private $htmlBlockRenderer;
23
24 78
    public function __construct(BlockRendererInterface $htmlBlockRenderer)
25
    {
26 78
        $this->htmlBlockRenderer = $htmlBlockRenderer;
27 78
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 9
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
33
    {
34 9
        $rendered = $this->htmlBlockRenderer->render($block, $htmlRenderer, $inTightList);
35
36 9
        if ($rendered === '') {
37
            return '';
38
        }
39
40
        // Match these types of tags: <title> </title> <title x="sdf"> <title/> <title />
41 9
        return preg_replace('/<(\/?(?:title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext)[ \/>])/i', '&lt;$1', $rendered);
0 ignored issues
show
Bug Compatibility introduced by
The expression preg_replace('/<(\\/?(?:..., '&lt;$1', $rendered); of type string|string[] adds the type string[] to the return on line 41 which is incompatible with the return type declared by the interface League\CommonMark\Block\...ndererInterface::render of type League\CommonMark\HtmlElement|string|null.
Loading history...
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 78
    public function setConfiguration(ConfigurationInterface $configuration)
48
    {
49 78
        if ($this->htmlBlockRenderer instanceof ConfigurationAwareInterface) {
50 78
            $this->htmlBlockRenderer->setConfiguration($configuration);
51
        }
52 78
    }
53
}
54