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