Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Result often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Result, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | final class Result implements \Countable, \SeekableIterator, \ArrayAccess |
||
| 17 | { |
||
| 18 | |||
| 19 | const MYSQL_TYPE_BIT = 16; |
||
| 20 | const MYSQL_TYPE_BLOB = 252; |
||
| 21 | const MYSQL_TYPE_DATE = 10; |
||
| 22 | const MYSQL_TYPE_DATETIME = 12; |
||
| 23 | const MYSQL_TYPE_DECIMAL = 0; |
||
| 24 | const MYSQL_TYPE_DOUBLE = 5; |
||
| 25 | const MYSQL_TYPE_ENUM = 247; |
||
| 26 | const MYSQL_TYPE_FLOAT = 4; |
||
| 27 | const MYSQL_TYPE_GEOMETRY = 255; |
||
| 28 | const MYSQL_TYPE_INT24 = 9; |
||
| 29 | const MYSQL_TYPE_JSON = 245; |
||
| 30 | const MYSQL_TYPE_LONG = 3; |
||
| 31 | const MYSQL_TYPE_LONGLONG = 8; |
||
| 32 | const MYSQL_TYPE_LONG_BLOB = 251; |
||
| 33 | const MYSQL_TYPE_MEDIUM_BLOB = 250; |
||
| 34 | const MYSQL_TYPE_NEWDATE = 14; |
||
| 35 | const MYSQL_TYPE_NEWDECIMAL = 246; |
||
| 36 | const MYSQL_TYPE_NULL = 6; |
||
| 37 | const MYSQL_TYPE_SET = 248; |
||
| 38 | const MYSQL_TYPE_SHORT = 2; |
||
| 39 | const MYSQL_TYPE_STRING = 254; |
||
| 40 | const MYSQL_TYPE_TIME = 11; |
||
| 41 | const MYSQL_TYPE_TIMESTAMP = 7; |
||
| 42 | const MYSQL_TYPE_TINY = 1; |
||
| 43 | const MYSQL_TYPE_TINY_BLOB = 249; |
||
| 44 | const MYSQL_TYPE_VARCHAR = 15; |
||
| 45 | const MYSQL_TYPE_VAR_STRING = 253; |
||
| 46 | const MYSQL_TYPE_YEAR = 13; |
||
| 47 | |||
| 48 | const RESULT_TYPE_ARRAY = 'array'; |
||
| 49 | const RESULT_TYPE_ARRAYY = 'Arrayy'; |
||
| 50 | const RESULT_TYPE_OBJECT = 'object'; |
||
| 51 | const RESULT_TYPE_YIELD = 'yield'; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var int |
||
| 55 | */ |
||
| 56 | public $num_rows; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | public $sql; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var \mysqli_result|\Doctrine\DBAL\Statement |
||
| 65 | */ |
||
| 66 | private $_result; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var int |
||
| 70 | */ |
||
| 71 | private $current_row; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var \Closure|null |
||
| 75 | */ |
||
| 76 | private $_mapper; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | private $_default_result_type = self::RESULT_TYPE_OBJECT; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var \mysqli_stmt|null |
||
| 85 | */ |
||
| 86 | private $doctrineMySQLiStmt; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var \Doctrine\DBAL\Driver\PDOStatement|null |
||
| 90 | */ |
||
| 91 | private $doctrinePdoStmt; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var int |
||
| 95 | */ |
||
| 96 | private $doctrinePdoStmtDataSeekFake = 0; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var int |
||
| 100 | */ |
||
| 101 | private $doctrinePdoStmtDataSeekInit = false; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | private $doctrinePdoStmtDataSeekFakeCache = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Result constructor. |
||
| 110 | * |
||
| 111 | * @param string $sql |
||
| 112 | * @param \mysqli_result|\Doctrine\DBAL\Statement $result |
||
| 113 | * @param \Closure $mapper Optional callback mapper for the "fetchCallable()" method |
||
| 114 | */ |
||
| 115 | 118 | public function __construct(string $sql, $result, \Closure $mapper = null) |
|
| 163 | |||
| 164 | /** |
||
| 165 | * __destruct |
||
| 166 | */ |
||
| 167 | 117 | public function __destruct() |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Runs a user-provided callback with the MySQLi_Result object given as |
||
| 174 | * argument and returns the result, or returns the MySQLi_Result object if |
||
| 175 | * called without an argument. |
||
| 176 | * |
||
| 177 | * @param callable $callback User-provided callback (optional) |
||
| 178 | * |
||
| 179 | * @return mixed|\Doctrine\DBAL\Statement|\mysqli_result |
||
| 180 | */ |
||
| 181 | 2 | public function __invoke(callable $callback = null) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Get the current "num_rows" as string. |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | public function __toString() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Cast data into int, float or string. |
||
| 202 | * |
||
| 203 | * <p> |
||
| 204 | * <br /> |
||
| 205 | * INFO: install / use "mysqlnd"-driver for better performance |
||
| 206 | * </p> |
||
| 207 | * |
||
| 208 | * @param array|object $data |
||
| 209 | * |
||
| 210 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 211 | */ |
||
| 212 | 82 | private function cast(&$data) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Countable interface implementation. |
||
| 285 | * |
||
| 286 | * @return int The number of rows in the result |
||
| 287 | */ |
||
| 288 | 2 | public function count(): int |
|
| 292 | |||
| 293 | /** |
||
| 294 | * Iterator interface implementation. |
||
| 295 | * |
||
| 296 | * @return mixed The current element |
||
| 297 | */ |
||
| 298 | 8 | public function current() |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Iterator interface implementation. |
||
| 305 | * |
||
| 306 | * @return int The current element key (row index; zero-based) |
||
| 307 | */ |
||
| 308 | 1 | public function key(): int |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Iterator interface implementation. |
||
| 315 | * |
||
| 316 | * @return void |
||
| 317 | */ |
||
| 318 | 8 | public function next() |
|
| 322 | |||
| 323 | /** |
||
| 324 | * Iterator interface implementation. |
||
| 325 | * |
||
| 326 | * @param int $row Row position to rewind to; defaults to 0 |
||
| 327 | * |
||
| 328 | * @return void |
||
| 329 | */ |
||
| 330 | 12 | public function rewind($row = 0) |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Moves the internal pointer to the specified row position. |
||
| 339 | * |
||
| 340 | * @param int $row <p>Row position; zero-based and set to 0 by default</p> |
||
| 341 | * |
||
| 342 | * @return bool <p>true on success, false otherwise</p> |
||
| 343 | */ |
||
| 344 | 20 | public function seek($row = 0): bool |
|
| 371 | |||
| 372 | /** |
||
| 373 | * Iterator interface implementation. |
||
| 374 | * |
||
| 375 | * @return bool <p>true if the current index is valid, false otherwise</p> |
||
| 376 | */ |
||
| 377 | 8 | public function valid(): bool |
|
| 381 | |||
| 382 | /** |
||
| 383 | * Fetch. |
||
| 384 | * |
||
| 385 | * <p> |
||
| 386 | * <br /> |
||
| 387 | * INFO: this will return an object by default, not an array<br /> |
||
| 388 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 389 | * </p> |
||
| 390 | * |
||
| 391 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 392 | * |
||
| 393 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 394 | */ |
||
| 395 | 6 | public function fetch(bool $reset = false) |
|
| 411 | |||
| 412 | /** |
||
| 413 | * Fetch all results. |
||
| 414 | * |
||
| 415 | * <p> |
||
| 416 | * <br /> |
||
| 417 | * INFO: this will return an object by default, not an array<br /> |
||
| 418 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 419 | * </p> |
||
| 420 | * |
||
| 421 | * @return array |
||
| 422 | */ |
||
| 423 | 6 | public function fetchAll(): array |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Fetch all results as array. |
||
| 442 | * |
||
| 443 | * @return array |
||
| 444 | */ |
||
| 445 | 28 | public function fetchAllArray(): array |
|
| 461 | |||
| 462 | /** |
||
| 463 | * Fetch all results as "Arrayy"-object. |
||
| 464 | * |
||
| 465 | * @return Arrayy |
||
| 466 | */ |
||
| 467 | 10 | public function fetchAllArrayy(): Arrayy |
|
| 483 | |||
| 484 | /** |
||
| 485 | * Fetch a single column as an 1-dimension array. |
||
| 486 | * |
||
| 487 | * @param string $column |
||
| 488 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: false</p> |
||
| 489 | * |
||
| 490 | * @return array <p>Return an empty array if the "$column" wasn't found</p> |
||
| 491 | */ |
||
| 492 | 2 | public function fetchAllColumn(string $column, bool $skipNullValues = false): array |
|
| 496 | |||
| 497 | /** |
||
| 498 | * Fetch all results as array with objects. |
||
| 499 | * |
||
| 500 | * @param object|string $class <p> |
||
| 501 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 502 | * parameter)<br> |
||
| 503 | * <strong>object</strong>: use a object and fill the the data into |
||
| 504 | * </p> |
||
| 505 | * @param null|array $params optional |
||
| 506 | * <p> |
||
| 507 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 508 | * string. |
||
| 509 | * </p> |
||
| 510 | * |
||
| 511 | * @return array |
||
| 512 | */ |
||
| 513 | 17 | public function fetchAllObject($class = '', array $params = null): array |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Fetch all results as "\Generator" via yield. |
||
| 564 | * |
||
| 565 | * @param object|string $class <p> |
||
| 566 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 567 | * parameter)<br> |
||
| 568 | * <strong>object</strong>: use a object and fill the the data into |
||
| 569 | * </p> |
||
| 570 | * @param null|array $params optional |
||
| 571 | * <p> |
||
| 572 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 573 | * string. |
||
| 574 | * </p> |
||
| 575 | * |
||
| 576 | * @return \Generator |
||
| 577 | */ |
||
| 578 | 5 | public function fetchAllYield($class = '', array $params = null): \Generator |
|
| 624 | |||
| 625 | /** |
||
| 626 | * Fetch as array. |
||
| 627 | * |
||
| 628 | * @param bool $reset |
||
| 629 | * |
||
| 630 | * @return array|false <p><strong>false</strong> on error</p> |
||
| 631 | */ |
||
| 632 | 30 | View Code Duplication | public function fetchArray(bool $reset = false) |
| 649 | |||
| 650 | /** |
||
| 651 | * Fetch data as a key/value pair array. |
||
| 652 | * |
||
| 653 | * <p> |
||
| 654 | * <br /> |
||
| 655 | * INFO: both "key" and "value" must exists in the fetched data |
||
| 656 | * the key will be the new key of the result-array |
||
| 657 | * <br /><br /> |
||
| 658 | * </p> |
||
| 659 | * |
||
| 660 | * e.g.: |
||
| 661 | * <code> |
||
| 662 | * fetchArrayPair('some_id', 'some_value'); |
||
| 663 | * // array(127 => 'some value', 128 => 'some other value') |
||
| 664 | * </code> |
||
| 665 | * |
||
| 666 | * @param string $key |
||
| 667 | * @param string $value |
||
| 668 | * |
||
| 669 | * @return array |
||
| 670 | */ |
||
| 671 | 3 | public function fetchArrayPair(string $key, string $value): array |
|
| 690 | |||
| 691 | /** |
||
| 692 | * Fetch as "Arrayy"-object. |
||
| 693 | * |
||
| 694 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 695 | * |
||
| 696 | * @return Arrayy|false <p><strong>false</strong> on error</p> |
||
| 697 | */ |
||
| 698 | 6 | View Code Duplication | public function fetchArrayy(bool $reset = false) |
| 715 | |||
| 716 | /** |
||
| 717 | * Fetches a row or a single column within a row. Returns null if there are |
||
| 718 | * no more rows in the result. |
||
| 719 | * |
||
| 720 | * @param int $row The row number (optional) |
||
| 721 | * @param string $column The column name (optional) |
||
| 722 | * |
||
| 723 | * @return mixed An associative array or a scalar value |
||
| 724 | */ |
||
| 725 | 17 | public function fetchCallable(int $row = null, string $column = null) |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Fetch a single column as string (or as 1-dimension array). |
||
| 758 | * |
||
| 759 | * @param string $column |
||
| 760 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: true</p> |
||
| 761 | * @param bool $asArray <p>Get all values and not only the last one. | default: false</p> |
||
| 762 | * |
||
| 763 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 764 | * "$asArray"</p> |
||
| 765 | */ |
||
| 766 | 9 | public function fetchColumn(string $column = '', bool $skipNullValues = true, bool $asArray = false) |
|
| 767 | { |
||
| 768 | 9 | if ($asArray === false) { |
|
| 769 | 7 | $columnData = ''; |
|
| 770 | |||
| 771 | 7 | $data = $this->fetchAllArrayy()->reverse(); |
|
| 772 | 7 | View Code Duplication | foreach ($data as $_row) { |
| 773 | |||
| 774 | 7 | if ($skipNullValues === true) { |
|
| 775 | 7 | if (isset($_row[$column]) === false) { |
|
| 776 | 7 | continue; |
|
| 777 | } |
||
| 778 | 3 | } elseif (\array_key_exists($column, $_row) === false) { |
|
| 779 | break; |
||
| 780 | } |
||
| 781 | |||
| 782 | 7 | $columnData = $_row[$column]; |
|
| 783 | 7 | break; |
|
| 784 | } |
||
| 785 | |||
| 786 | 7 | return $columnData; |
|
| 787 | } |
||
| 788 | |||
| 789 | // -- return as array --> |
||
| 790 | |||
| 791 | 2 | $columnData = []; |
|
| 792 | |||
| 793 | 2 | View Code Duplication | foreach ($this->fetchAllYield() as $_row) { |
| 794 | |||
| 795 | 2 | if ($skipNullValues === true) { |
|
| 796 | if (isset($_row->{$column}) === false) { |
||
| 797 | continue; |
||
| 798 | } |
||
| 799 | 2 | } elseif (\array_key_exists($column, $_row) === false) { |
|
| 800 | break; |
||
| 801 | } |
||
| 802 | |||
| 803 | 2 | $columnData[] = $_row->{$column}; |
|
| 804 | } |
||
| 805 | |||
| 806 | 2 | return $columnData; |
|
| 807 | } |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Return rows of field information in a result set. |
||
| 811 | * |
||
| 812 | * @param bool $as_array Return each field info as array; defaults to false |
||
| 813 | * |
||
| 814 | * @return array Array of field information each as an associative array |
||
| 815 | */ |
||
| 816 | 1 | public function fetchFields(bool $as_array = false): array |
|
| 829 | |||
| 830 | /** |
||
| 831 | * Returns all rows at once as a grouped array of scalar values or arrays. |
||
| 832 | * |
||
| 833 | * @param string $group The column name to use for grouping |
||
| 834 | * @param string $column The column name to use as values (optional) |
||
| 835 | * |
||
| 836 | * @return array A grouped array of scalar values or arrays |
||
| 837 | */ |
||
| 838 | 1 | View Code Duplication | public function fetchGroups(string $group, string $column = null): array |
| 866 | |||
| 867 | /** |
||
| 868 | * Fetch as object. |
||
| 869 | * |
||
| 870 | * @param object|string $class <p> |
||
| 871 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 872 | * parameter)<br> |
||
| 873 | * <strong>object</strong>: use a object and fill the the data into |
||
| 874 | * </p> |
||
| 875 | * @param null|array $params optional |
||
| 876 | * <p> |
||
| 877 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 878 | * string. |
||
| 879 | * </p> |
||
| 880 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 881 | * |
||
| 882 | * @return object|false <p><strong>false</strong> on error</p> |
||
| 883 | */ |
||
| 884 | 32 | View Code Duplication | public function fetchObject($class = '', array $params = null, bool $reset = false) |
| 929 | |||
| 930 | /** |
||
| 931 | * Returns all rows at once as key-value pairs. |
||
| 932 | * |
||
| 933 | * @param string $key The column name to use as keys |
||
| 934 | * @param string $column The column name to use as values (optional) |
||
| 935 | * |
||
| 936 | * @return array An array of key-value pairs |
||
| 937 | */ |
||
| 938 | 1 | View Code Duplication | public function fetchPairs(string $key, string $column = null): array |
| 966 | |||
| 967 | /** |
||
| 968 | * Returns all rows at once, transposed as an array of arrays. Instead of |
||
| 969 | * returning rows of columns, this method returns columns of rows. |
||
| 970 | * |
||
| 971 | * @param string $column The column name to use as keys (optional) |
||
| 972 | * |
||
| 973 | * @return mixed A transposed array of arrays |
||
| 974 | */ |
||
| 975 | 1 | public function fetchTranspose(string $column = null) |
|
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Fetch as "\Generator" via yield. |
||
| 1003 | * |
||
| 1004 | * @param object|string $class <p> |
||
| 1005 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 1006 | * parameter)<br> |
||
| 1007 | * <strong>object</strong>: use a object and fill the the data into |
||
| 1008 | * </p> |
||
| 1009 | * @param null|array $params optional |
||
| 1010 | * <p> |
||
| 1011 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 1012 | * string. |
||
| 1013 | * </p> |
||
| 1014 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 1015 | * |
||
| 1016 | * @return \Generator |
||
| 1017 | */ |
||
| 1018 | 4 | View Code Duplication | public function fetchYield($class = '', array $params = null, bool $reset = false): \Generator |
| 1063 | |||
| 1064 | /** |
||
| 1065 | * @return mixed |
||
| 1066 | */ |
||
| 1067 | 94 | private function fetch_assoc() |
|
| 1107 | |||
| 1108 | /** |
||
| 1109 | * @return array|bool |
||
| 1110 | */ |
||
| 1111 | 1 | private function fetch_fields() |
|
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Returns the first row element from the result. |
||
| 1158 | * |
||
| 1159 | * @param string $column The column name to use as value (optional) |
||
| 1160 | * |
||
| 1161 | * @return mixed A row array or a single scalar value |
||
| 1162 | */ |
||
| 1163 | 3 | public function first(string $column = null) |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * free the memory |
||
| 1174 | */ |
||
| 1175 | 117 | public function free() |
|
| 1204 | |||
| 1205 | /** |
||
| 1206 | * alias for "Result->fetch()" |
||
| 1207 | * |
||
| 1208 | * @see Result::fetch() |
||
| 1209 | * |
||
| 1210 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 1211 | */ |
||
| 1212 | 3 | public function get() |
|
| 1216 | |||
| 1217 | /** |
||
| 1218 | * alias for "Result->fetchAll()" |
||
| 1219 | * |
||
| 1220 | * @see Result::fetchAll() |
||
| 1221 | * |
||
| 1222 | * @return array |
||
| 1223 | */ |
||
| 1224 | 3 | public function getAll(): array |
|
| 1228 | |||
| 1229 | /** |
||
| 1230 | * alias for "Result->fetchAllColumn()" |
||
| 1231 | * |
||
| 1232 | * @see Result::fetchAllColumn() |
||
| 1233 | * |
||
| 1234 | * @param string $column |
||
| 1235 | * @param bool $skipNullValues |
||
| 1236 | * |
||
| 1237 | * @return array |
||
| 1238 | */ |
||
| 1239 | public function getAllColumn(string $column, bool $skipNullValues = false): array |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * alias for "Result->fetchAllArray()" |
||
| 1246 | * |
||
| 1247 | * @see Result::fetchAllArray() |
||
| 1248 | * |
||
| 1249 | * @return array |
||
| 1250 | */ |
||
| 1251 | 3 | public function getArray(): array |
|
| 1255 | |||
| 1256 | /** |
||
| 1257 | * alias for "Result->fetchAllArrayy()" |
||
| 1258 | * |
||
| 1259 | * @see Result::fetchAllArrayy() |
||
| 1260 | * |
||
| 1261 | * @return Arrayy |
||
| 1262 | */ |
||
| 1263 | public function getArrayy(): Arrayy |
||
| 1267 | |||
| 1268 | /** |
||
| 1269 | * alias for "Result->fetchColumn()" |
||
| 1270 | * |
||
| 1271 | * @see Result::fetchColumn() |
||
| 1272 | * |
||
| 1273 | * @param string $column |
||
| 1274 | * @param bool $asArray |
||
| 1275 | * @param bool $skipNullValues |
||
| 1276 | * |
||
| 1277 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 1278 | * "$asArray"</p> |
||
| 1279 | */ |
||
| 1280 | 3 | public function getColumn(string $column, bool $skipNullValues = true, bool $asArray = false) |
|
| 1284 | |||
| 1285 | /** |
||
| 1286 | * @return string |
||
| 1287 | */ |
||
| 1288 | 3 | public function getDefaultResultType(): string |
|
| 1292 | |||
| 1293 | /** |
||
| 1294 | * alias for "Result->fetchAllObject()" |
||
| 1295 | * |
||
| 1296 | * @see Result::fetchAllObject() |
||
| 1297 | * |
||
| 1298 | * @return array of mysql-objects |
||
| 1299 | */ |
||
| 1300 | 3 | public function getObject(): array |
|
| 1304 | |||
| 1305 | /** |
||
| 1306 | * alias for "Result->fetchAllYield()" |
||
| 1307 | * |
||
| 1308 | * @see Result::fetchAllYield() |
||
| 1309 | * |
||
| 1310 | * @param bool $asArray |
||
| 1311 | * |
||
| 1312 | * @return \Generator |
||
| 1313 | */ |
||
| 1314 | 1 | public function getYield($asArray = false): \Generator |
|
| 1315 | { |
||
| 1316 | 1 | return $this->fetchAllYield($asArray); |
|
| 1317 | } |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * Check if the result is empty. |
||
| 1321 | * |
||
| 1322 | * @return bool |
||
| 1323 | */ |
||
| 1324 | 58 | public function is_empty(): bool |
|
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Fetch all results as "json"-string. |
||
| 1331 | * |
||
| 1332 | * @return string |
||
| 1333 | */ |
||
| 1334 | 3 | public function json(): string |
|
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Returns the last row element from the result. |
||
| 1343 | * |
||
| 1344 | * @param string $column The column name to use as value (optional) |
||
| 1345 | * |
||
| 1346 | * @return mixed A row array or a single scalar value |
||
| 1347 | */ |
||
| 1348 | 3 | public function last(string $column = null) |
|
| 1356 | |||
| 1357 | /** |
||
| 1358 | * Set the mapper... |
||
| 1359 | * |
||
| 1360 | * @param \Closure $callable |
||
| 1361 | * |
||
| 1362 | * @return $this |
||
| 1363 | */ |
||
| 1364 | 1 | public function map(\Closure $callable): self |
|
| 1370 | |||
| 1371 | /** |
||
| 1372 | * Alias of count(). Deprecated. |
||
| 1373 | * |
||
| 1374 | * @return int The number of rows in the result |
||
| 1375 | */ |
||
| 1376 | 1 | public function num_rows(): int |
|
| 1380 | |||
| 1381 | /** |
||
| 1382 | * ArrayAccess interface implementation. |
||
| 1383 | * |
||
| 1384 | * @param int $offset <p>Offset number</p> |
||
| 1385 | * |
||
| 1386 | * @return bool <p>true if offset exists, false otherwise</p> |
||
| 1387 | */ |
||
| 1388 | 1 | public function offsetExists($offset): bool |
|
| 1392 | |||
| 1393 | /** |
||
| 1394 | * ArrayAccess interface implementation. |
||
| 1395 | * |
||
| 1396 | * @param int $offset Offset number |
||
| 1397 | * |
||
| 1398 | * @return mixed |
||
| 1399 | */ |
||
| 1400 | 1 | public function offsetGet($offset) |
|
| 1408 | |||
| 1409 | /** |
||
| 1410 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1411 | * |
||
| 1412 | * @param mixed $offset |
||
| 1413 | * @param mixed $value |
||
| 1414 | */ |
||
| 1415 | public function offsetSet($offset, $value) |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1423 | * |
||
| 1424 | * @param mixed $offset |
||
| 1425 | */ |
||
| 1426 | public function offsetUnset($offset) |
||
| 1431 | |||
| 1432 | /** |
||
| 1433 | * Reset the offset (data_seek) for the results. |
||
| 1434 | * |
||
| 1435 | * @return Result |
||
| 1436 | */ |
||
| 1437 | 54 | public function reset(): self |
|
| 1462 | |||
| 1463 | /** |
||
| 1464 | * You can set the default result-type to Result::RESULT_TYPE_*. |
||
| 1465 | * |
||
| 1466 | * INFO: used for "fetch()" and "fetchAll()" |
||
| 1467 | * |
||
| 1468 | * @param string $default_result_type |
||
| 1469 | */ |
||
| 1470 | 6 | public function setDefaultResultType(string $default_result_type = self::RESULT_TYPE_OBJECT) |
|
| 1484 | |||
| 1485 | /** |
||
| 1486 | * @param int $offset |
||
| 1487 | * @param null|int $length |
||
| 1488 | * @param bool $preserve_keys |
||
| 1489 | * |
||
| 1490 | * @return array |
||
| 1491 | */ |
||
| 1492 | 1 | public function slice(int $offset = 0, int $length = null, bool $preserve_keys = false): array |
|
| 1518 | } |
||
| 1519 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: