Completed
Push — master ( 9292e6...a84270 )
by Colin
03:12 queued 02:10
created

DisallowedRawHtmlRenderer::setConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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\Configuration\ConfigurationAwareInterface;
15
use League\CommonMark\Configuration\ConfigurationInterface;
16
use League\CommonMark\Node\Node;
17
use League\CommonMark\Renderer\ChildNodeRendererInterface;
18
use League\CommonMark\Renderer\NodeRendererInterface;
19
20
final class DisallowedRawHtmlRenderer implements NodeRendererInterface, ConfigurationAwareInterface
21
{
22
    /** @var NodeRendererInterface */
23
    private $innerRenderer;
24
25 78
    public function __construct(NodeRendererInterface $innerRenderer)
26
    {
27 78
        $this->innerRenderer = $innerRenderer;
28 78
    }
29
30 9
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
31
    {
32 9
        $rendered = $this->innerRenderer->render($node, $childRenderer);
33
34 9
        if ($rendered === '') {
35
            return '';
36
        }
37
38
        // Match these types of tags: <title> </title> <title x="sdf"> <title/> <title />
39 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 39 which is incompatible with the return type declared by the interface League\CommonMark\Render...ndererInterface::render of type League\CommonMark\Util\HtmlElement|string|null.
Loading history...
40
    }
41
42 78
    public function setConfiguration(ConfigurationInterface $configuration): void
43
    {
44 78
        if ($this->innerRenderer instanceof ConfigurationAwareInterface) {
45 78
            $this->innerRenderer->setConfiguration($configuration);
46
        }
47 78
    }
48
}
49