1 | <?php |
||
16 | class Result implements IteratorAggregate |
||
17 | { |
||
18 | /** |
||
19 | * @var PreparedStatement |
||
20 | */ |
||
21 | private $statement; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $batch_size; |
||
27 | |||
28 | /** |
||
29 | * @var Mapper[] list of Mappers to apply when fetching results |
||
30 | */ |
||
31 | private $mappers; |
||
32 | |||
33 | /** |
||
34 | * @var Indexer|null |
||
35 | */ |
||
36 | private $indexer = null; |
||
37 | |||
38 | /** |
||
39 | * @param PreparedStatement $statement prepared statement |
||
40 | * @param int $batch_size batch-size (when fetching large result sets) |
||
41 | * @param Mapper[] $mappers list of Mappers to apply while fetching results |
||
42 | * @param Indexer|null $indexer optional Indexer (used to customize Generator keys) |
||
43 | */ |
||
44 | 1 | public function __construct(PreparedStatement $statement, $batch_size, array $mappers, Indexer $indexer = null) |
|
51 | |||
52 | /** |
||
53 | * @return mixed|null first record of the record-set (or NULL, if the record-set is empty) |
||
54 | */ |
||
55 | 1 | public function firstRow() |
|
63 | |||
64 | /** |
||
65 | * @return mixed|null first column value of the first record of the record-set (or NULL, if the record-set is empty) |
||
66 | */ |
||
67 | 1 | public function firstCol() |
|
77 | |||
78 | /** |
||
79 | * @return array all the records of the record-set |
||
80 | * |
||
81 | * @throws RuntimeException if the result-set contains overlapping keys (generated by an Indexer) |
||
82 | */ |
||
83 | 1 | public function all() |
|
106 | |||
107 | /** |
||
108 | * Execute this Statement and return a Generator, so you can iterate over the results. |
||
109 | * |
||
110 | * This method implements `IteratorAggregate`, permitting you to iterate directly over |
||
111 | * the resulting records (or objects) without explicitly having to call this method. |
||
112 | * |
||
113 | * @return Iterator |
||
114 | */ |
||
115 | 1 | public function getIterator() |
|
119 | |||
120 | /** |
||
121 | * Create an Iterator with a given batch-size. |
||
122 | * |
||
123 | * @param int $batch_size batch-size when processing the result set |
||
124 | * |
||
125 | * @return Iterator |
||
126 | */ |
||
127 | 1 | private function createIterator($batch_size) |
|
179 | } |
||
180 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.