AlertBlockRenderer::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
ccs 0
cts 5
cp 0
cc 2
nc 2
nop 3
crap 6
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
}