AlertBlockParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 2
1
<?php
2
3
namespace App\Markdown\Parser;
4
5
use League\CommonMark\Block\Parser\BlockParserInterface;
6
use League\CommonMark\ContextInterface;
7
use League\CommonMark\Cursor;
8
use App\Markdown\Element\AlertBlock;
9
10
class AlertBlockParser implements BlockParserInterface {
11
12
    /**
13
     * @inheritDoc
14
     */
15
    public function parse(ContextInterface $context, Cursor $cursor): bool {
16
        $previousState = $cursor->saveState();
17
18
        $alert = $cursor->match('/^!{3}([a-z]+)/');
19
        if($alert === null) {
20
            $cursor->restoreState($previousState);
21
            return false;
22
        }
23
24
        $type = substr($alert, 3);
25
26
        $context->addBlock(new AlertBlock($type));
27
28
        return true;
29
    }
30
}