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

DisallowedRawHtmlBlockRenderer.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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