ListItemNode   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDepth() 0 3 1
A toSyntax() 0 16 3
A __construct() 0 13 4
1
<?php
2
3
/**
4
 * Created by IntelliJ IDEA.
5
 * User: michael
6
 * Date: 7/7/17
7
 * Time: 4:10 PM
8
 */
9
10
namespace dokuwiki\plugin\prosemirror\parser;
11
12
class ListItemNode extends Node
13
{
14
    protected $parent;
15
    /** @var Node[] */
16
    protected $subnodes = [];
17
18
    /**
19
     * ListItemNode constructor.
20
     *
21
     * @param          $data
22
     * @param ListNode $parent
23
     */
24
    public function __construct($data, Node $parent)
25
    {
26
        $this->parent = &$parent;
27
28
        foreach ($data['content'] as $node) {
29
            if ($node['type'] === 'list_content') {
30
                foreach ($node['content'] as $subnode) {
31
                    $this->subnodes[] = self::getSubNode($subnode, $this);
32
                }
33
                continue;
34
            }
35
36
            $this->subnodes[] = self::getSubNode($node, $this);
37
        }
38
    }
39
40
    public function toSyntax()
41
    {
42
        $lines = [];
43
        foreach ($this->subnodes as $node) {
44
            /*
45
             * only sublists may start with a linebreak, other blocks, like <code> must not have a linebreak before them
46
             * or DokuWiki will interprete this as a new block altogether, instead as something that is part of the
47
             * current <li>
48
             */
49
            $prefixLinebreak = '';
50
            if ($node instanceof ListNode) {
51
                $prefixLinebreak = "\n";
52
            }
53
            $lines[] = $prefixLinebreak . $node->toSyntax();
54
        }
55
        return implode("", $lines);
56
    }
57
58
    public function getDepth()
59
    {
60
        return $this->parent->getDepth();
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

60
        return $this->parent->/** @scrutinizer ignore-call */ getDepth();
Loading history...
61
    }
62
}
63