Node::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
crap 12
1
<?php
2
3
namespace tomzx\HtmlParser;
4
5
use DOMNode;
6
use tomzx\AbstractParser\NodeInterface;
7
8
class Node implements NodeInterface
9
{
10
    protected $node;
11
12
    protected $children = [];
13
14
    public function __construct(DOMNode $node)
15
    {
16
        $this->node = $node;
17
        if ($this->node->hasChildNodes()) {
18
            foreach ($this->node->childNodes as $child) {
19
                $this->children[] = new Node($child);
20
            }
21
        }
22
    }
23
24
    public function &getChildren()
25
    {
26
//        if (!$this->node->hasChildNodes()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
//            return [];
28
//        }
29
//
30
//        $children = [];
31
//        foreach ($this->node->childNodes as $child) {
32
//            $children[] = new Node($child);
33
//        }
34
//        return $children;
35
        return $this->children;
36
    }
37
38
//    public function setChild($index, NodeInterface $node)
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
//    {
40
//        $this->children[$index] = $node;
41
//    }
42
43
    public function hasChildren()
44
    {
45
        return $this->node->hasChildNodes();
46
    }
47
48
    public function getNode()
49
    {
50
        return $this->node;
51
    }
52
53
    public function __debugInfo()
54
    {
55
        return [
56
            'name' => $this->node->nodeName,
57
            'children' => $this->children,
58
        ];
59
    }
60
}
61