RootNode::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
/**
4
 * Created by IntelliJ IDEA.
5
 * User: michael
6
 * Date: 7/7/17
7
 * Time: 1:49 PM
8
 */
9
10
namespace dokuwiki\plugin\prosemirror\parser;
11
12
class RootNode extends Node
13
{
14
    /** @var Node[] */
15
    protected $subnodes = [];
16
17
    protected $attr = [];
18
19
    public function __construct($data, Node $ignored = null)
20
    {
21
        $this->attr = $data['attrs'] ?? null;
22
        foreach ($data['content'] as $node) {
23
            $this->subnodes[] = self::getSubNode($node, $this);
24
        }
25
    }
26
27
    public function toSyntax()
28
    {
29
        $doc = '';
30
        foreach ($this->subnodes as $subnode) {
31
            $doc .= $subnode->toSyntax();
32
            $doc = rtrim($doc);
33
            $doc .= "\n\n";
34
        }
35
        $doc .= $this->getMacroSyntax();
36
        return $doc;
37
    }
38
39
    /**
40
     * Get the syntax for each active macro
41
     *
42
     * This produces the syntax representation for the and NOCACHE NOTOC macros
43
     *
44
     * @return string empty string or a string with a line for each active macro
45
     */
46
    protected function getMacroSyntax()
47
    {
48
        $syntax = '';
49
        if (!empty($this->attr['nocache'])) {
50
            $syntax .= "~~NOCACHE~~\n";
51
        }
52
        if (!empty($this->attr['notoc'])) {
53
            $syntax .= "~~NOTOC~~\n";
54
        }
55
        return $syntax;
56
    }
57
}
58