HeadingNode::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * Created by IntelliJ IDEA.
5
 * User: michael
6
 * Date: 7/7/17
7
 * Time: 4:49 PM
8
 */
9
10
namespace dokuwiki\plugin\prosemirror\parser;
11
12
class HeadingNode extends Node
13
{
14
    protected $parent;
15
    protected $level;
16
    protected $text;
17
18
    public function __construct($data, Node $parent)
19
    {
20
        if (trim($data['content'][0]['text']) === '') {
21
            return;
22
        }
23
24
        $this->parent = &$parent;
25
        $this->level = $data['attrs']['level'];
26
        $this->text = $data['content'][0]['text'];
27
    }
28
29
    public function toSyntax()
30
    {
31
        $wrapper = [
32
            1 => '======',
33
            2 => '=====',
34
            3 => '====',
35
            4 => '===',
36
            5 => '==',
37
        ];
38
39
        return $wrapper[$this->level] . ' ' . $this->text . ' ' . $wrapper[$this->level];
40
    }
41
}
42