2525abstract class BaseResult implements ResultInterface
2626{
2727 /**
28- * Connection ID
29- *
3028 * @var TConnection
3129 */
3230 public $ connID ;
3331
3432 /**
35- * Result ID
36- *
3733 * @var false|TResult
3834 */
3935 public $ resultID ;
4036
4137 /**
42- * Result Array
43- *
4438 * @var list<array>
4539 */
4640 public $ resultArray = [];
4741
4842 /**
49- * Result Object
50- *
5143 * @var list<object>
5244 */
5345 public $ resultObject = [];
5446
5547 /**
56- * Custom Result Object
57- *
58- * @var array
48+ * @var array<class-string, list<object>>
5949 */
6050 public $ customResultObject = [];
6151
6252 /**
63- * Current Row index
53+ * Current row index
6454 *
6555 * @var int
6656 */
@@ -74,15 +64,11 @@ abstract class BaseResult implements ResultInterface
7464 protected $ numRows ;
7565
7666 /**
77- * Row data
78- *
79- * @var array|null
67+ * @var array<string, mixed>|null
8068 */
8169 public $ rowData ;
8270
8371 /**
84- * Constructor
85- *
8672 * @param TConnection $connID
8773 * @param TResult $resultID
8874 */
@@ -92,13 +78,6 @@ public function __construct(&$connID, &$resultID)
9278 $ this ->resultID = $ resultID ;
9379 }
9480
95- /**
96- * Retrieve the results of the query. Typically an array of
97- * individual data rows, which can be either an 'array', an
98- * 'object', or a custom class name.
99- *
100- * @param string $type The row type. Either 'array', 'object', or a class name to use
101- */
10281 public function getResult (string $ type = 'object ' ): array
10382 {
10483 if ($ type === 'array ' ) {
@@ -112,13 +91,6 @@ public function getResult(string $type = 'object'): array
11291 return $ this ->getCustomResultObject ($ type );
11392 }
11493
115- /**
116- * Returns the results as an array of custom objects.
117- *
118- * @param class-string $className
119- *
120- * @return array
121- */
12294 public function getCustomResultObject (string $ className )
12395 {
12496 if (isset ($ this ->customResultObject [$ className ])) {
@@ -165,11 +137,6 @@ public function getCustomResultObject(string $className)
165137 return $ this ->customResultObject [$ className ];
166138 }
167139
168- /**
169- * Returns the results as an array of arrays.
170- *
171- * If no results, an empty array is returned.
172- */
173140 public function getResultArray (): array
174141 {
175142 if ($ this ->resultArray !== []) {
@@ -202,13 +169,6 @@ public function getResultArray(): array
202169 return $ this ->resultArray ;
203170 }
204171
205- /**
206- * Returns the results as an array of objects.
207- *
208- * If no results, an empty array is returned.
209- *
210- * @return list<stdClass>
211- */
212172 public function getResultObject (): array
213173 {
214174 if ($ this ->resultObject !== []) {
@@ -245,19 +205,6 @@ public function getResultObject(): array
245205 return $ this ->resultObject ;
246206 }
247207
248- /**
249- * Wrapper object to return a row as either an array, an object, or
250- * a custom class.
251- *
252- * If the row doesn't exist, returns null.
253- *
254- * @template T of object
255- *
256- * @param int|string $n The index of the results to return, or column name.
257- * @param 'array'|'object'|class-string<T> $type The type of result object. 'array', 'object' or class name.
258- *
259- * @return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)))
260- */
261208 public function getRow ($ n = 0 , string $ type = 'object ' )
262209 {
263210 // $n is a column name.
@@ -286,18 +233,6 @@ public function getRow($n = 0, string $type = 'object')
286233 return $ this ->getCustomRowObject ($ n , $ type );
287234 }
288235
289- /**
290- * Returns a row as a custom class instance.
291- *
292- * If the row doesn't exist, returns null.
293- *
294- * @template T of object
295- *
296- * @param int $n The index of the results to return.
297- * @param class-string<T> $className
298- *
299- * @return T|null
300- */
301236 public function getCustomRowObject (int $ n , string $ className )
302237 {
303238 if (! isset ($ this ->customResultObject [$ className ])) {
@@ -315,13 +250,6 @@ public function getCustomRowObject(int $n, string $className)
315250 return $ this ->customResultObject [$ className ][$ this ->currentRow ] ?? null ;
316251 }
317252
318- /**
319- * Returns a single row from the results as an array.
320- *
321- * If row doesn't exist, returns null.
322- *
323- * @return array|null
324- */
325253 public function getRowArray (int $ n = 0 )
326254 {
327255 $ result = $ this ->getResultArray ();
@@ -336,13 +264,6 @@ public function getRowArray(int $n = 0)
336264 return $ result [$ this ->currentRow ] ?? null ;
337265 }
338266
339- /**
340- * Returns a single row from the results as an object.
341- *
342- * If row doesn't exist, returns null.
343- *
344- * @return object|stdClass|null
345- */
346267 public function getRowObject (int $ n = 0 )
347268 {
348269 $ result = $ this ->getResultObject ();
@@ -357,14 +278,6 @@ public function getRowObject(int $n = 0)
357278 return $ result [$ this ->currentRow ] ?? null ;
358279 }
359280
360- /**
361- * Assigns an item into a particular column slot.
362- *
363- * @param array|string $key
364- * @param array|object|stdClass|null $value
365- *
366- * @return void
367- */
368281 public function setRow ($ key , $ value = null )
369282 {
370283 // We cache the row data for subsequent uses
@@ -385,29 +298,20 @@ public function setRow($key, $value = null)
385298 }
386299 }
387300
388- /**
389- * Returns the "first" row of the current results.
390- */
391301 public function getFirstRow (string $ type = 'object ' )
392302 {
393303 $ result = $ this ->getResult ($ type );
394304
395305 return ($ result === []) ? null : $ result [0 ];
396306 }
397307
398- /**
399- * Returns the "last" row of the current results.
400- */
401308 public function getLastRow (string $ type = 'object ' )
402309 {
403310 $ result = $ this ->getResult ($ type );
404311
405312 return ($ result === []) ? null : $ result [count ($ result ) - 1 ];
406313 }
407314
408- /**
409- * Returns the "next" row of the current results.
410- */
411315 public function getNextRow (string $ type = 'object ' )
412316 {
413317 $ result = $ this ->getResult ($ type );
@@ -418,9 +322,6 @@ public function getNextRow(string $type = 'object')
418322 return isset ($ result [$ this ->currentRow + 1 ]) ? $ result [++$ this ->currentRow ] : null ;
419323 }
420324
421- /**
422- * Returns the "previous" row of the current results.
423- */
424325 public function getPreviousRow (string $ type = 'object ' )
425326 {
426327 $ result = $ this ->getResult ($ type );
@@ -435,11 +336,6 @@ public function getPreviousRow(string $type = 'object')
435336 return $ result [$ this ->currentRow ] ?? null ;
436337 }
437338
438- /**
439- * Returns an unbuffered row and move the pointer to the next row.
440- *
441- * @return array|object|null
442- */
443339 public function getUnbufferedRow (string $ type = 'object ' )
444340 {
445341 if ($ type === 'array ' ) {
@@ -478,43 +374,12 @@ private function isValidResultId(): bool
478374 return is_resource ($ this ->resultID ) || is_object ($ this ->resultID );
479375 }
480376
481- /**
482- * Gets the number of fields in the result set.
483- */
484- abstract public function getFieldCount (): int ;
485-
486- /**
487- * Generates an array of column names in the result set.
488- */
489- abstract public function getFieldNames (): array ;
490-
491- /**
492- * Generates an array of objects representing field meta-data.
493- */
494- abstract public function getFieldData (): array ;
495-
496- /**
497- * Frees the current result.
498- *
499- * @return void
500- */
501- abstract public function freeResult ();
502-
503- /**
504- * Moves the internal pointer to the desired offset. This is called
505- * internally before fetching results to make sure the result set
506- * starts at zero.
507- *
508- * @return bool
509- */
510- abstract public function dataSeek (int $ n = 0 );
511-
512377 /**
513378 * Returns the result set as an array.
514379 *
515380 * Overridden by driver classes.
516381 *
517- * @return array|false|null
382+ * @return array<string, mixed> |false|null
518383 */
519384 abstract protected function fetchAssoc ();
520385
0 commit comments