Node   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 53
ccs 0
cts 28
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A getChildren() 0 13 1
A hasChildren() 0 4 1
A getNode() 0 4 1
A __debugInfo() 0 7 1
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