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