55use ByJG \AnyDataset \Core \GenericIterator ;
66use ByJG \AnyDataset \Core \IteratorFilter ;
77use ByJG \AnyDataset \Core \Row ;
8- use InvalidArgumentException ;
98
109class ArrayDatasetIterator extends GenericIterator
1110{
1211
1312 /**
1413 * @var array
1514 */
16- protected $ rows ;
15+ protected array $ rows ;
1716
1817 /**
1918 * Enter description here...
2019 *
2120 * @var array
2221 */
23- protected $ keys ;
22+ protected array $ keys ;
2423
2524 /**
2625 /* @var int
2726 */
28- protected $ index ;
27+ protected int $ index ;
2928
3029 /**
3130 * @var Row
3231 */
33- protected $ currentRow ;
32+ protected ? Row $ currentRow ;
3433
3534 /**
36- * @var IteratorFilter
35+ * @var IteratorFilter|null
3736 */
38- protected $ filter ;
37+ protected ? IteratorFilter $ filter ;
3938 /**
40- * @var mixed| string
39+ * @var string|null
4140 */
42- protected $ propertyIndexName ;
41+ protected ? string $ propertyIndexName ;
4342 /**
44- * @var mixed| string
43+ * @var string|null
4544 */
46- protected $ propertyKeyName ;
45+ protected ? string $ propertyKeyName ;
4746
4847 /**
4948 * @param array $rows
50- * @param IteratorFilter $filter
49+ * @param IteratorFilter|null $filter
50+ * @param string|null $propertyIndexName
51+ * @param string|null $propertyKeyName
5152 */
52- public function __construct ($ rows , $ filter , $ propertyIndexName = "__id " , $ propertyKeyName = "__key " )
53+ public function __construct (array $ rows , ? IteratorFilter $ filter , ? string $ propertyIndexName = "__id " , ? string $ propertyKeyName = "__key " )
5354 {
54- if (!is_array ($ rows )) {
55- throw new InvalidArgumentException ("ArrayDatasetIterator must receive an array " );
56- }
5755 $ this ->index = 0 ;
5856 $ this ->currentRow = null ;
5957 $ this ->rows = $ rows ;
@@ -62,13 +60,12 @@ public function __construct($rows, $filter, $propertyIndexName = "__id", $proper
6260
6361 $ this ->propertyIndexName = $ propertyIndexName ;
6462 $ this ->propertyKeyName = $ propertyKeyName ;
65-
6663 }
6764
6865 /**
6966 * @return int
7067 */
71- public function count ()
68+ public function count (): int
7269 {
7370 return count ($ this ->rows );
7471 }
@@ -77,7 +74,7 @@ public function count()
7774 * @return bool
7875 * @throws \ByJG\Serializer\Exception\InvalidArgumentException
7976 */
80- public function hasNext ()
77+ public function hasNext (): bool
8178 {
8279 if (!empty ($ this ->currentRow )) {
8380 return true ;
@@ -114,10 +111,10 @@ public function hasNext()
114111 }
115112
116113 /**
117- * @return Row
114+ * @return Row|null
118115 * @throws \ByJG\Serializer\Exception\InvalidArgumentException
119116 */
120- public function moveNext ()
117+ public function moveNext (): ? Row
121118 {
122119 if (!$ this ->hasNext ()) {
123120 return null ;
@@ -129,7 +126,7 @@ public function moveNext()
129126 return $ row ;
130127 }
131128
132- public function key ()
129+ public function key (): int
133130 {
134131 return $ this ->index ;
135132 }
0 commit comments