Completed
Push — master ( 2031fa...cf579d )
by Rigel Kent
01:29
created

RecursiveDOMIterator::hasChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cion\TextToSpeech\Sources;
4
5
use DOMNode;
6
use RecursiveIterator;
7
8
class RecursiveDOMIterator implements RecursiveIterator
9
{
10
    /**
11
     * Current Position in DOMNodeList
12
     * @var Integer
13
     */
14
    protected $_position;
15
16
    /**
17
     * The DOMNodeList with all children to iterate over
18
     * @var DOMNodeList
19
     */
20
    protected $_nodeList;
21
22
    /**
23
     * @param DOMNode $domNode
24
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
     */
26
    public function __construct(DOMNode $domNode)
27
    {
28
        $this->_position = 0;
29
        $this->_nodeList = $domNode->childNodes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $domNode->childNodes of type object<DOMNodeList> is incompatible with the declared type object<Cion\TextToSpeech\Sources\DOMNodeList> of property $_nodeList.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    /**
33
     * Returns the current DOMNode
34
     * @return DOMNode
35
     */
36
    public function current()
37
    {
38
        return $this->_nodeList->item($this->_position);
39
    }
40
41
    /**
42
     * Returns an iterator for the current iterator entry
43
     * @return RecursiveDOMIterator
44
     */
45
    public function getChildren()
46
    {
47
        return new self($this->current());
48
    }
49
50
    /**
51
     * Returns if an iterator can be created for the current entry.
52
     * @return Boolean
53
     */
54
    public function hasChildren()
55
    {
56
        return $this->current()->hasChildNodes();
57
    }
58
59
    /**
60
     * Returns the current position
61
     * @return Integer
62
     */
63
    public function key()
64
    {
65
        return $this->_position;
66
    }
67
68
    /**
69
     * Moves the current position to the next element.
70
     * @return void
71
     */
72
    public function next()
73
    {
74
        $this->_position++;
75
    }
76
77
    /**
78
     * Rewind the Iterator to the first element
79
     * @return void
80
     */
81
    public function rewind()
82
    {
83
        $this->_position = 0;
84
    }
85
86
    /**
87
     * Checks if current position is valid
88
     * @return Boolean
89
     */
90
    public function valid()
91
    {
92
        return $this->_position < $this->_nodeList->length;
93
    }
94
}
95