Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
DomIterator
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
8 / 8
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 current
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getChildren
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasChildren
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 key
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 next
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rewind
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 valid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Dom;
15
16use ReturnTypeWillChange;
17
18/**
19 * Dom iterator class
20 *
21 * @category   Pop
22 * @package    Pop\Dom
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    3.3.0
27 */
28class DomIterator implements \RecursiveIterator
29{
30
31    /**
32     * Current position
33     * @var int
34     */
35    protected $position;
36
37    /**
38     * Node List
39     * @var \DOMNodeList
40     */
41    protected $nodeList;
42
43    /**
44     * Constructor
45     *
46     * Instantiate the DOM iterator object
47     *
48     * @param \DOMNode $domNode
49     */
50    public function __construct(\DOMNode $domNode)
51    {
52        $this->position = 0;
53        $this->nodeList = $domNode->childNodes;
54    }
55
56    /**
57     * Get current method
58     * @return \DOMNode
59     */
60    #[ReturnTypeWillChange]
61    public function current()
62    {
63        return $this->nodeList->item($this->position);
64    }
65
66    /**
67     * Get children method
68     * @return DomIterator
69     */
70    #[ReturnTypeWillChange]
71    public function getChildren()
72    {
73        return new self($this->current());
74    }
75
76    /**
77     * Has children method
78     * @return bool
79     */
80    public function hasChildren(): bool
81    {
82        return $this->current()->hasChildNodes();
83    }
84
85    /**
86     * Key method
87     * @return int
88     */
89    public function key(): int
90    {
91        return $this->position;
92    }
93
94    /**
95     * Next method
96     */
97    #[ReturnTypeWillChange]
98    public function next()
99    {
100        $this->position++;
101    }
102
103    /**
104     * Rewind method
105     */
106    #[ReturnTypeWillChange]
107    public function rewind()
108    {
109        $this->position = 0;
110    }
111
112    /**
113     * Is valid method
114     * @return bool
115     */
116    public function valid(): bool
117    {
118        return $this->position < $this->nodeList->length;
119    }
120
121}