AlertBlockRenderer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 13
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 8 2
1
<?php
2
3
namespace App\Markdown\Renderer;
4
5
use InvalidArgumentException;
6
use App\Markdown\Element\AlertBlock;
7
use League\CommonMark\Block\Element\AbstractBlock;
8
use League\CommonMark\Block\Renderer\BlockRendererInterface;
9
use League\CommonMark\ElementRendererInterface;
10
use League\CommonMark\HtmlElement;
11
12
class AlertBlockRenderer implements BlockRendererInterface {
13
14
    /**
15
     * @inheritDoc
16
     */
17
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false): string|HtmlElement|null {
18
        if(!$block instanceof AlertBlock) {
19
            throw new InvalidArgumentException(sprintf('$block must be of type "%s" ("%s" given)', AlertBlock::class, $block::class));
20
        }
21
22
        return new HtmlElement('div', [
23
            'class' => 'alert alert-' . $block->getType(),
24
        ], $htmlRenderer->renderBlocks($block->children()));
25
    }
26
}