ListNode   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 22
c 2
b 1
f 0
dl 0
loc 44
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDepth() 0 3 1
A __construct() 0 11 4
A toSyntax() 0 15 4
1
<?php
2
3
/**
4
 * Created by IntelliJ IDEA.
5
 * User: michael
6
 * Date: 7/7/17
7
 * Time: 4:06 PM
8
 */
9
10
namespace dokuwiki\plugin\prosemirror\parser;
11
12
class ListNode extends Node
13
{
14
    protected $parent;
15
    /** @var string */
16
    protected $prefix;
17
    /** @var ListItemNode[] */
18
    protected $listItemNodes = [];
19
20
    protected $depth = 0;
21
22
    public function __construct($data, Node $parent)
23
    {
24
        $this->parent = &$parent;
25
        if (is_a($this->parent, 'dokuwiki\plugin\prosemirror\parser\ListItemNode')) {
26
            $this->depth = $this->parent->getDepth() + 1;
0 ignored issues
show
Bug introduced by
The method getDepth() does not exist on dokuwiki\plugin\prosemirror\parser\Node. It seems like you code against a sub-type of dokuwiki\plugin\prosemirror\parser\Node such as dokuwiki\plugin\prosemirror\parser\ListItemNode or dokuwiki\plugin\prosemirror\parser\ListNode. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            $this->depth = $this->parent->/** @scrutinizer ignore-call */ getDepth() + 1;
Loading history...
27
        }
28
29
        $this->prefix = $data['type'] == 'bullet_list' ? '  *' : '  -';
30
31
        foreach ($data['content'] as $listItemNode) {
32
            $this->listItemNodes[] = new ListItemNode($listItemNode, $this);
33
        }
34
    }
35
36
    public function toSyntax()
37
    {
38
        $doc = '';
39
40
        foreach ($this->listItemNodes as $li) {
41
            $liText = str_repeat('  ', $this->depth);
42
            $liText .= $this->prefix;
43
            $lines = $li->toSyntax();
44
            if (!empty($lines) && $lines[0] !== ' ') {
45
                $liText .= ' ';
46
            }
47
            $liText .= $lines . "\n";
48
            $doc .= $liText;
49
        }
50
        return rtrim($doc); // blocks should __not__ end with a newline, parents must handle breaks between children
51
    }
52
53
    public function getDepth()
54
    {
55
        return $this->depth;
56
    }
57
}
58