1111namespace xPDO ;
1212
1313
14+ use Iterator ;
15+ use PDO ;
16+ use PDOStatement ;
17+ use xPDO \Om \xPDOQuery ;
18+
1419/**
1520 * An iterable representation of an xPDOObject result set.
1621 *
2025 *
2126 * @package xpdo
2227 */
23- class xPDOIterator implements \Iterator {
28+ class xPDOIterator implements Iterator
29+ {
2430 private $ xpdo = null ;
2531 private $ index = 0 ;
2632 private $ current = null ;
27- /** @var null|\ PDOStatement */
33+ /** @var null|PDOStatement */
2834 private $ stmt = null ;
2935 private $ class = null ;
30- private $ alias = null ;
31- /** @var null|int|string|array|\xPDO\Om\ xPDOQuery */
36+ private $ alias ;
37+ /** @var null|int|string|array|xPDOQuery */
3238 private $ criteria = null ;
3339 private $ criteriaType = 'xPDOQuery ' ;
3440 private $ cacheFlag = false ;
3541
3642 /**
3743 * Construct a new xPDOIterator instance (do not call directly).
3844 *
39- * @see xPDO::getIterator()
4045 * @param xPDO &$xpdo A reference to a valid xPDO instance.
4146 * @param array $options An array of options for the iterator.
4247 * @return xPDOIterator An xPDOIterator instance.
48+ * @see xPDO::getIterator()
4349 */
44- function __construct (& $ xpdo , array $ options = array ()) {
50+ public function __construct (xPDO &$ xpdo , array $ options = [])
51+ {
4552 $ this ->xpdo =& $ xpdo ;
4653 if (isset ($ options ['class ' ])) {
4754 $ this ->class = $ this ->xpdo ->loadClass ($ options ['class ' ]);
@@ -67,9 +74,12 @@ function __construct(& $xpdo, array $options= array()) {
6774 $ this ->alias = $ this ->criteria ->getAlias ();
6875 }
6976 }
77+
78+ return $ this ;
7079 }
7180
72- public function rewind () {
81+ public function rewind ()
82+ {
7383 $ this ->index = 0 ;
7484 if (!empty ($ this ->stmt )) {
7585 $ this ->stmt ->closeCursor ();
@@ -86,15 +96,18 @@ public function rewind() {
8696 }
8797 }
8898
89- public function current () {
99+ public function current ()
100+ {
90101 return $ this ->current ;
91102 }
92103
93- public function key () {
104+ public function key ()
105+ {
94106 return $ this ->index ;
95107 }
96108
97- public function next () {
109+ public function next ()
110+ {
98111 $ this ->fetch ();
99112 if (!$ this ->valid ()) {
100113 $ this ->index = null ;
@@ -104,7 +117,8 @@ public function next() {
104117 return $ this ->current ();
105118 }
106119
107- public function valid () {
120+ public function valid (): bool
121+ {
108122 return ($ this ->current !== null );
109123 }
110124
@@ -114,10 +128,15 @@ public function valid() {
114128 * Calls the _loadInstance() method for the specified class, so it properly
115129 * inherits behavior from xPDOObject derivatives.
116130 */
117- protected function fetch () {
118- $ row = $ this ->stmt ->fetch (\PDO ::FETCH_ASSOC );
131+ protected function fetch ()
132+ {
133+ $ row = $ this ->stmt ->fetch (PDO ::FETCH_ASSOC );
119134 if (is_array ($ row ) && !empty ($ row )) {
120- $ instance = $ this ->xpdo ->call ($ this ->class , '_loadInstance ' , array (& $ this ->xpdo , $ this ->class , $ this ->alias , $ row ));
135+ $ instance = $ this ->xpdo ->call (
136+ $ this ->class ,
137+ '_loadInstance ' ,
138+ [& $ this ->xpdo , $ this ->class , $ this ->alias , $ row ]
139+ );
121140 if ($ instance === null ) {
122141 $ this ->fetch ();
123142 } else {
0 commit comments