These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ByJG\AnyDataset\Repository; |
||
4 | |||
5 | use ByJG\AnyDataset\Repository\GenericIterator; |
||
6 | use ByJG\AnyDataset\Repository\SingleRow; |
||
7 | use DOMNodeList; |
||
8 | |||
9 | /** |
||
10 | * Iterator class is a structure used to navigate forward in a AnyDataset structure. |
||
11 | */ |
||
12 | class AnyIterator extends GenericIterator |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Row Elements |
||
17 | * @var array |
||
18 | */ |
||
19 | private $_list; |
||
20 | |||
21 | /** |
||
22 | * Current row number |
||
23 | * @var int |
||
24 | */ |
||
25 | private $_curRow; //int |
||
26 | |||
27 | /** |
||
28 | * Iterator constructor |
||
29 | * @param DOMNodeList $list \DOMNodeList |
||
30 | * @return void |
||
31 | */ |
||
0 ignored issues
–
show
|
|||
32 | |||
33 | public function __construct($list) |
||
34 | { |
||
35 | $this->_curRow = 0; |
||
36 | $this->_list = $list; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * How many elements have |
||
41 | * @return int |
||
42 | */ |
||
43 | public function count() |
||
44 | { |
||
45 | return sizeof($this->_list); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Ask the Iterator is exists more rows. Use before moveNext method. |
||
50 | * @return bool True if exist more rows, otherwise false |
||
51 | */ |
||
52 | public function hasNext() |
||
53 | { |
||
54 | return ($this->_curRow < $this->count()); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Return the next row. |
||
59 | * @return SingleRow |
||
60 | */ |
||
61 | public function moveNext() |
||
62 | { |
||
63 | if (!$this->hasNext()) { |
||
64 | return null; |
||
65 | } else { |
||
66 | return $this->_list[$this->_curRow++]; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | function key() |
||
71 | { |
||
72 | return $this->_curRow; |
||
73 | } |
||
74 | } |
||
75 |
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.