13
13
*
14
14
* It implements `IteratorAggregate`, allowing you to execute the query and iterate
15
15
* over the result set with a `foreach` statement.
16
+ *
17
+ * @implements IteratorAggregate<array<string,mixed>>
16
18
*/
17
19
class Result implements IteratorAggregate
18
20
{
19
- /**
20
- * @var PreparedStatement
21
- */
22
- private $ statement ;
23
-
24
- /**
25
- * @var int
26
- */
27
- private $ batch_size ;
21
+ private PreparedStatement $ statement ;
22
+ private int $ batch_size ;
28
23
29
24
/**
30
25
* @var Mapper[] list of Mappers to apply when fetching results
31
26
*/
32
- private $ mappers ;
27
+ private array $ mappers ;
33
28
34
29
/**
35
30
* @param PreparedStatement $statement prepared statement
36
31
* @param int $batch_size batch-size (when fetching large result sets)
37
32
* @param Mapper[] $mappers list of Mappers to apply while fetching results
38
33
*/
39
- public function __construct (PreparedStatement $ statement , $ batch_size , array $ mappers )
34
+ public function __construct (PreparedStatement $ statement , int $ batch_size , array $ mappers )
40
35
{
41
36
$ this ->statement = $ statement ;
42
37
$ this ->batch_size = $ batch_size ;
43
38
$ this ->mappers = $ mappers ;
44
39
}
45
40
46
41
/**
47
- * @return mixed|null first record of the record-set (or NULL, if the record-set is empty)
42
+ * @return array<string, mixed> |null first record of the record-set (or NULL, if the record-set is empty)
48
43
*/
49
- public function firstRow ()
44
+ public function firstRow (): array | null
50
45
{
51
46
foreach ($ this ->createIterator (1 ) as $ record ) {
52
47
return $ record ; // break from loop immediately after fetching the first record
@@ -58,7 +53,7 @@ public function firstRow()
58
53
/**
59
54
* @return mixed|null first column value of the first record of the record-set (or NULL, if the record-set is empty)
60
55
*/
61
- public function firstCol ()
56
+ public function firstCol (): mixed
62
57
{
63
58
foreach ($ this ->createIterator (1 ) as $ record ) {
64
59
$ keys = array_keys ($ record );
@@ -70,9 +65,9 @@ public function firstCol()
70
65
}
71
66
72
67
/**
73
- * @return array all the records of the record-set
68
+ * @return array<array<string,mixed>> all the records of the record-set
74
69
*/
75
- public function all ()
70
+ public function all (): array
76
71
{
77
72
return iterator_to_array ($ this ->getIterator ());
78
73
}
@@ -95,7 +90,7 @@ public function getIterator(): Traversable
95
90
*
96
91
* @return Iterator
97
92
*/
98
- private function createIterator ($ batch_size )
93
+ private function createIterator ($ batch_size ): Iterator
99
94
{
100
95
$ fetching = true ;
101
96
0 commit comments