Issues (7)

src/Sources/RecursiveDOMIterator.php (2 issues)

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 int
13
     */
14
    protected $_position;
15
16
    /**
17
     * The DOMNodeList with all children to iterate over.
0 ignored issues
show
The type Cion\TextToSpeech\Sources\DOMNodeList was not found. Did you mean DOMNodeList? If so, make sure to prefix the type with \.
Loading history...
18
     * @var DOMNodeList
19
     */
20
    protected $_nodeList;
21
22
    /**
23
     * @param DOMNode $domNode
24
     */
25
    public function __construct(DOMNode $domNode)
26
    {
27
        $this->_position = 0;
28
        $this->_nodeList = $domNode->childNodes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $domNode->childNodes of type DOMNodeList is incompatible with the declared type 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...
29
    }
30
31
    /**
32
     * Returns the current DOMNode.
33
     * @return DOMNode
34
     */
35
    public function current()
36
    {
37
        return $this->_nodeList->item($this->_position);
38
    }
39
40
    /**
41
     * Returns an iterator for the current iterator entry.
42
     * @return RecursiveDOMIterator
43
     */
44
    public function getChildren()
45
    {
46
        return new self($this->current());
47
    }
48
49
    /**
50
     * Returns if an iterator can be created for the current entry.
51
     * @return bool
52
     */
53
    public function hasChildren()
54
    {
55
        return $this->current()->hasChildNodes();
56
    }
57
58
    /**
59
     * Returns the current position.
60
     * @return int
61
     */
62
    public function key()
63
    {
64
        return $this->_position;
65
    }
66
67
    /**
68
     * Moves the current position to the next element.
69
     * @return void
70
     */
71
    public function next()
72
    {
73
        $this->_position++;
74
    }
75
76
    /**
77
     * Rewind the Iterator to the first element.
78
     * @return void
79
     */
80
    public function rewind()
81
    {
82
        $this->_position = 0;
83
    }
84
85
    /**
86
     * Checks if current position is valid.
87
     * @return bool
88
     */
89
    public function valid()
90
    {
91
        return $this->_position < $this->_nodeList->length;
92
    }
93
}
94