Completed
Push — master ( ddd96c...50ed96 )
by TJ
54s
created

ParsedownAlert   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 48
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A blockAlert() 0 15 2
A blockAlertContinue() 0 16 3
A blockAlertComplete() 0 7 1
1
<?php
2
3
namespace sixlive;
4
5
class ParsedownAlert extends \Parsedown
6
{
7 1
    public function __construct()
8
    {
9 1
        $this->BlockTypes[':'] = ['Alert'];
10 1
    }
11
12 1
    protected function blockAlert($block)
13
    {
14 1
        if (preg_match('/::: (.*)/', $block['text'], $matches)) {
15
            return [
16 1
                'char' => ':',
17
                'element' => [
18 1
                    'name' => 'div',
19 1
                    'text' => '',
20
                    'attributes' => [
21 1
                        'class' => "alert-{$matches[1]}",
22
                    ],
23
                ],
24
            ];
25
        }
26
    }
27
28 1
    protected function blockAlertContinue($line, $block)
29
    {
30 1
        if (isset($block['complete'])) {
31
            return;
32
        }
33
34 1
        if (preg_match('/:::/', $line['text'], $matches)) {
35 1
            $block['complete'] = true;
36
37 1
            return $block;
38
        }
39
40 1
        $block['element']['text'] .= $line['text']."\n";
41
42 1
        return $block;
43
    }
44
45 1
    protected function blockAlertComplete($block)
46
    {
47 1
        $block['element']['rawHtml'] = $this->text($block['element']['text']);
48 1
        unset($block['element']['text']);
49
50 1
        return $block;
51
    }
52
}
53