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 |
||
| 14 | final class Result implements \Countable, \SeekableIterator, \ArrayAccess |
||
| 15 | { |
||
| 16 | const MYSQL_TYPE_BIT = 16; |
||
| 17 | |||
| 18 | const MYSQL_TYPE_BLOB = 252; |
||
| 19 | |||
| 20 | const MYSQL_TYPE_DATE = 10; |
||
| 21 | |||
| 22 | const MYSQL_TYPE_DATETIME = 12; |
||
| 23 | |||
| 24 | const MYSQL_TYPE_DECIMAL = 0; |
||
| 25 | |||
| 26 | const MYSQL_TYPE_DOUBLE = 5; |
||
| 27 | |||
| 28 | const MYSQL_TYPE_ENUM = 247; |
||
| 29 | |||
| 30 | const MYSQL_TYPE_FLOAT = 4; |
||
| 31 | |||
| 32 | const MYSQL_TYPE_GEOMETRY = 255; |
||
| 33 | |||
| 34 | const MYSQL_TYPE_INT24 = 9; |
||
| 35 | |||
| 36 | const MYSQL_TYPE_JSON = 245; |
||
| 37 | |||
| 38 | const MYSQL_TYPE_LONG = 3; |
||
| 39 | |||
| 40 | const MYSQL_TYPE_LONGLONG = 8; |
||
| 41 | |||
| 42 | const MYSQL_TYPE_LONG_BLOB = 251; |
||
| 43 | |||
| 44 | const MYSQL_TYPE_MEDIUM_BLOB = 250; |
||
| 45 | |||
| 46 | const MYSQL_TYPE_NEWDATE = 14; |
||
| 47 | |||
| 48 | const MYSQL_TYPE_NEWDECIMAL = 246; |
||
| 49 | |||
| 50 | const MYSQL_TYPE_NULL = 6; |
||
| 51 | |||
| 52 | const MYSQL_TYPE_SET = 248; |
||
| 53 | |||
| 54 | const MYSQL_TYPE_SHORT = 2; |
||
| 55 | |||
| 56 | const MYSQL_TYPE_STRING = 254; |
||
| 57 | |||
| 58 | const MYSQL_TYPE_TIME = 11; |
||
| 59 | |||
| 60 | const MYSQL_TYPE_TIMESTAMP = 7; |
||
| 61 | |||
| 62 | const MYSQL_TYPE_TINY = 1; |
||
| 63 | |||
| 64 | const MYSQL_TYPE_TINY_BLOB = 249; |
||
| 65 | |||
| 66 | const MYSQL_TYPE_VARCHAR = 15; |
||
| 67 | |||
| 68 | const MYSQL_TYPE_VAR_STRING = 253; |
||
| 69 | |||
| 70 | const MYSQL_TYPE_YEAR = 13; |
||
| 71 | |||
| 72 | const RESULT_TYPE_ARRAY = 'array'; |
||
| 73 | |||
| 74 | const RESULT_TYPE_ARRAYY = 'Arrayy'; |
||
| 75 | |||
| 76 | const RESULT_TYPE_OBJECT = 'object'; |
||
| 77 | |||
| 78 | const RESULT_TYPE_YIELD = 'yield'; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var int |
||
| 82 | */ |
||
| 83 | public $num_rows; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string |
||
| 87 | */ |
||
| 88 | public $sql; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var \Doctrine\DBAL\Statement|\mysqli_result |
||
| 92 | */ |
||
| 93 | private $_result; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var int |
||
| 97 | */ |
||
| 98 | private $current_row; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var \Closure|null |
||
| 102 | */ |
||
| 103 | private $_mapper; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var string |
||
| 107 | */ |
||
| 108 | private $_default_result_type = self::RESULT_TYPE_OBJECT; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var \mysqli_stmt|null |
||
| 112 | */ |
||
| 113 | private $doctrineMySQLiStmt; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var \Doctrine\DBAL\Driver\PDOStatement|null |
||
| 117 | */ |
||
| 118 | private $doctrinePdoStmt; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var int |
||
| 122 | */ |
||
| 123 | private $doctrinePdoStmtDataSeekFake = 0; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var int |
||
| 127 | */ |
||
| 128 | private $doctrinePdoStmtDataSeekInit = false; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var array |
||
| 132 | */ |
||
| 133 | private $doctrinePdoStmtDataSeekFakeCache = []; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Result constructor. |
||
| 137 | * |
||
| 138 | * @param string $sql |
||
| 139 | * @param \Doctrine\DBAL\Statement|\mysqli_result $result |
||
| 140 | * @param \Closure $mapper Optional callback mapper for the "fetchCallable()" method |
||
| 141 | */ |
||
| 142 | 101 | public function __construct(string $sql, $result, \Closure $mapper = null) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * __destruct |
||
| 191 | */ |
||
| 192 | 100 | public function __destruct() |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Runs a user-provided callback with the MySQLi_Result object given as |
||
| 199 | * argument and returns the result, or returns the MySQLi_Result object if |
||
| 200 | * called without an argument. |
||
| 201 | * |
||
| 202 | * @param callable $callback User-provided callback (optional) |
||
| 203 | * |
||
| 204 | * @return \Doctrine\DBAL\Statement|mixed|\mysqli_result |
||
| 205 | */ |
||
| 206 | 2 | public function __invoke(callable $callback = null) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * Get the current "num_rows" as string. |
||
| 217 | * |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | public function __toString() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Cast data into int, float or string. |
||
| 227 | * |
||
| 228 | * <p> |
||
| 229 | * <br /> |
||
| 230 | * INFO: install / use "mysqlnd"-driver for better performance |
||
| 231 | * </p> |
||
| 232 | * |
||
| 233 | * @param array|object $data |
||
| 234 | * |
||
| 235 | * @return array|false|object <p><strong>false</strong> on error</p> |
||
| 236 | */ |
||
| 237 | 68 | private function cast(&$data) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * Countable interface implementation. |
||
| 314 | * |
||
| 315 | * @return int The number of rows in the result |
||
| 316 | */ |
||
| 317 | 2 | public function count(): int |
|
| 321 | |||
| 322 | /** |
||
| 323 | * Iterator interface implementation. |
||
| 324 | * |
||
| 325 | * @return mixed The current element |
||
| 326 | */ |
||
| 327 | 8 | public function current() |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Iterator interface implementation. |
||
| 334 | * |
||
| 335 | * @return int The current element key (row index; zero-based) |
||
| 336 | */ |
||
| 337 | 1 | public function key(): int |
|
| 341 | |||
| 342 | /** |
||
| 343 | * Iterator interface implementation. |
||
| 344 | * |
||
| 345 | * @return void |
||
| 346 | */ |
||
| 347 | 8 | public function next() |
|
| 351 | |||
| 352 | /** |
||
| 353 | * Iterator interface implementation. |
||
| 354 | * |
||
| 355 | * @param int $row Row position to rewind to; defaults to 0 |
||
| 356 | * |
||
| 357 | * @return void |
||
| 358 | */ |
||
| 359 | 12 | public function rewind($row = 0) |
|
| 365 | |||
| 366 | /** |
||
| 367 | * Moves the internal pointer to the specified row position. |
||
| 368 | * |
||
| 369 | * @param int $row <p>Row position; zero-based and set to 0 by default</p> |
||
| 370 | * |
||
| 371 | * @return bool <p>true on success, false otherwise</p> |
||
| 372 | */ |
||
| 373 | 20 | public function seek($row = 0): bool |
|
| 399 | |||
| 400 | /** |
||
| 401 | * Iterator interface implementation. |
||
| 402 | * |
||
| 403 | * @return bool <p>true if the current index is valid, false otherwise</p> |
||
| 404 | */ |
||
| 405 | 8 | public function valid(): bool |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Fetch. |
||
| 412 | * |
||
| 413 | * <p> |
||
| 414 | * <br /> |
||
| 415 | * INFO: this will return an object by default, not an array<br /> |
||
| 416 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 417 | * </p> |
||
| 418 | * |
||
| 419 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 420 | * |
||
| 421 | * @return array|false|object <p><strong>false</strong> on error</p> |
||
| 422 | */ |
||
| 423 | 6 | public function fetch(bool $reset = false) |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Fetch all results. |
||
| 442 | * |
||
| 443 | * <p> |
||
| 444 | * <br /> |
||
| 445 | * INFO: this will return an object by default, not an array<br /> |
||
| 446 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 447 | * </p> |
||
| 448 | * |
||
| 449 | * @return array |
||
| 450 | */ |
||
| 451 | 6 | public function fetchAll(): array |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Fetch all results as array. |
||
| 470 | * |
||
| 471 | * @return array |
||
| 472 | */ |
||
| 473 | 28 | public function fetchAllArray(): array |
|
| 489 | |||
| 490 | /** |
||
| 491 | * Fetch all results as "Arrayy"-object. |
||
| 492 | * |
||
| 493 | * @return Arrayy |
||
| 494 | */ |
||
| 495 | 10 | public function fetchAllArrayy(): Arrayy |
|
| 511 | |||
| 512 | /** |
||
| 513 | * Fetch a single column as an 1-dimension array. |
||
| 514 | * |
||
| 515 | * @param string $column |
||
| 516 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: false</p> |
||
| 517 | * |
||
| 518 | * @return array <p>Return an empty array if the "$column" wasn't found</p> |
||
| 519 | */ |
||
| 520 | 5 | public function fetchAllColumn(string $column, bool $skipNullValues = false): array |
|
| 524 | |||
| 525 | /** |
||
| 526 | * Fetch all results as array with objects. |
||
| 527 | * |
||
| 528 | * @param object|string $class <p> |
||
| 529 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 530 | * parameter)<br> |
||
| 531 | * <strong>object</strong>: use a object and fill the the data into |
||
| 532 | * </p> |
||
| 533 | * @param array|null $params optional |
||
| 534 | * <p> |
||
| 535 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 536 | * string. |
||
| 537 | * </p> |
||
| 538 | * |
||
| 539 | * @return array |
||
| 540 | */ |
||
| 541 | 9 | public function fetchAllObject($class = '', array $params = null): array |
|
| 583 | |||
| 584 | /** |
||
| 585 | * Fetch all results as "\Generator" via yield. |
||
| 586 | * |
||
| 587 | * @param object|string $class <p> |
||
| 588 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 589 | * parameter)<br> |
||
| 590 | * <strong>object</strong>: use a object and fill the the data into |
||
| 591 | * </p> |
||
| 592 | * @param array|null $params optional |
||
| 593 | * <p> |
||
| 594 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 595 | * string. |
||
| 596 | * </p> |
||
| 597 | * |
||
| 598 | * @return \Generator |
||
| 599 | */ |
||
| 600 | 8 | public function fetchAllYield($class = '', array $params = null): \Generator |
|
| 640 | |||
| 641 | /** |
||
| 642 | * Fetch as array. |
||
| 643 | * |
||
| 644 | * @param bool $reset |
||
| 645 | * |
||
| 646 | * @return array|false <p><strong>false</strong> on error</p> |
||
| 647 | */ |
||
| 648 | 30 | View Code Duplication | public function fetchArray(bool $reset = false) |
| 665 | |||
| 666 | /** |
||
| 667 | * Fetch data as a key/value pair array. |
||
| 668 | * |
||
| 669 | * <p> |
||
| 670 | * <br /> |
||
| 671 | * INFO: both "key" and "value" must exists in the fetched data |
||
| 672 | * the key will be the new key of the result-array |
||
| 673 | * <br /><br /> |
||
| 674 | * </p> |
||
| 675 | * |
||
| 676 | * e.g.: |
||
| 677 | * <code> |
||
| 678 | * fetchArrayPair('some_id', 'some_value'); |
||
| 679 | * // array(127 => 'some value', 128 => 'some other value') |
||
| 680 | * </code> |
||
| 681 | * |
||
| 682 | * @param string $key |
||
| 683 | * @param string $value |
||
| 684 | * |
||
| 685 | * @return array |
||
| 686 | */ |
||
| 687 | 3 | public function fetchArrayPair(string $key, string $value): array |
|
| 706 | |||
| 707 | /** |
||
| 708 | * Fetch as "Arrayy"-object. |
||
| 709 | * |
||
| 710 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 711 | * |
||
| 712 | * @return Arrayy|false <p><strong>false</strong> on error</p> |
||
| 713 | */ |
||
| 714 | 6 | View Code Duplication | public function fetchArrayy(bool $reset = false) |
| 731 | |||
| 732 | /** |
||
| 733 | * Fetches a row or a single column within a row. Returns null if there are |
||
| 734 | * no more rows in the result. |
||
| 735 | * |
||
| 736 | * @param int $row The row number (optional) |
||
| 737 | * @param string $column The column name (optional) |
||
| 738 | * |
||
| 739 | * @return mixed An associative array or a scalar value |
||
| 740 | */ |
||
| 741 | 17 | public function fetchCallable(int $row = null, string $column = null) |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Fetch a single column as string (or as 1-dimension array). |
||
| 774 | * |
||
| 775 | * @param string $column |
||
| 776 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: true</p> |
||
| 777 | * @param bool $asArray <p>Get all values and not only the last one. | default: false</p> |
||
| 778 | * |
||
| 779 | * @return array|string <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 780 | * "$asArray"</p> |
||
| 781 | */ |
||
| 782 | 9 | public function fetchColumn(string $column = '', bool $skipNullValues = true, bool $asArray = false) |
|
| 783 | { |
||
| 784 | 9 | if (!$asArray) { |
|
| 785 | 7 | $columnData = ''; |
|
| 786 | |||
| 787 | 7 | $data = $this->fetchAllArrayy()->reverse()->getArray(); |
|
| 788 | 7 | View Code Duplication | foreach ($data as $_row) { |
| 789 | 7 | if ($skipNullValues) { |
|
| 790 | 7 | if (!isset($_row[$column])) { |
|
| 791 | 7 | continue; |
|
| 792 | } |
||
| 793 | 3 | } elseif (!\array_key_exists($column, $_row)) { |
|
| 794 | 3 | break; |
|
| 795 | } |
||
| 796 | |||
| 797 | 7 | $columnData = $_row[$column]; |
|
| 798 | |||
| 799 | 7 | break; |
|
| 800 | } |
||
| 801 | |||
| 802 | 7 | return $columnData; |
|
| 803 | } |
||
| 804 | |||
| 805 | // -- return as array --> |
||
| 806 | |||
| 807 | 5 | $columnData = []; |
|
| 808 | |||
| 809 | 5 | View Code Duplication | foreach ($this->fetchAllYield() as $_row) { |
| 810 | 5 | if ($skipNullValues) { |
|
| 811 | 3 | if (!isset($_row->{$column})) { |
|
| 812 | 3 | continue; |
|
| 813 | } |
||
| 814 | 5 | } elseif (!\array_key_exists($column, $_row)) { |
|
| 815 | 3 | break; |
|
| 816 | } |
||
| 817 | |||
| 818 | 5 | $columnData[] = $_row->{$column}; |
|
| 819 | } |
||
| 820 | |||
| 821 | 5 | return $columnData; |
|
| 822 | } |
||
| 823 | |||
| 824 | /** |
||
| 825 | * Return rows of field information in a result set. |
||
| 826 | * |
||
| 827 | * @param bool $as_array Return each field info as array; defaults to false |
||
| 828 | * |
||
| 829 | * @return array Array of field information each as an associative array |
||
| 830 | */ |
||
| 831 | 1 | public function fetchFields(bool $as_array = false): array |
|
| 844 | |||
| 845 | /** |
||
| 846 | * Returns all rows at once as a grouped array of scalar values or arrays. |
||
| 847 | * |
||
| 848 | * @param string $group The column name to use for grouping |
||
| 849 | * @param string $column The column name to use as values (optional) |
||
| 850 | * |
||
| 851 | * @return array A grouped array of scalar values or arrays |
||
| 852 | */ |
||
| 853 | 1 | View Code Duplication | public function fetchGroups(string $group, string $column = null): array |
| 879 | |||
| 880 | /** |
||
| 881 | * Fetch as object. |
||
| 882 | * |
||
| 883 | * @param object|string $class <p> |
||
| 884 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 885 | * parameter)<br> |
||
| 886 | * <strong>object</strong>: use a object and fill the the data into |
||
| 887 | * </p> |
||
| 888 | * @param array|null $params optional |
||
| 889 | * <p> |
||
| 890 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 891 | * string. |
||
| 892 | * </p> |
||
| 893 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 894 | * |
||
| 895 | * @return false|object <p><strong>false</strong> on error</p> |
||
| 896 | */ |
||
| 897 | 21 | View Code Duplication | public function fetchObject($class = '', array $params = null, bool $reset = false) |
| 936 | |||
| 937 | /** |
||
| 938 | * Returns all rows at once as key-value pairs. |
||
| 939 | * |
||
| 940 | * @param string $key The column name to use as keys |
||
| 941 | * @param string $column The column name to use as values (optional) |
||
| 942 | * |
||
| 943 | * @return array An array of key-value pairs |
||
| 944 | */ |
||
| 945 | 1 | View Code Duplication | public function fetchPairs(string $key, string $column = null): array |
| 971 | |||
| 972 | /** |
||
| 973 | * Returns all rows at once, transposed as an array of arrays. Instead of |
||
| 974 | * returning rows of columns, this method returns columns of rows. |
||
| 975 | * |
||
| 976 | * @param string $column The column name to use as keys (optional) |
||
| 977 | * |
||
| 978 | * @return mixed A transposed array of arrays |
||
| 979 | */ |
||
| 980 | 1 | public function fetchTranspose(string $column = null) |
|
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Fetch as "\Generator" via yield. |
||
| 1009 | * |
||
| 1010 | * @param object|string $class <p> |
||
| 1011 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 1012 | * parameter)<br> |
||
| 1013 | * <strong>object</strong>: use a object and fill the the data into |
||
| 1014 | * </p> |
||
| 1015 | * @param array|null $params optional |
||
| 1016 | * <p> |
||
| 1017 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 1018 | * string. |
||
| 1019 | * </p> |
||
| 1020 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 1021 | * |
||
| 1022 | * @return \Generator |
||
| 1023 | */ |
||
| 1024 | 4 | View Code Duplication | public function fetchYield($class = '', array $params = null, bool $reset = false): \Generator |
| 1063 | |||
| 1064 | /** |
||
| 1065 | * @return mixed |
||
| 1066 | */ |
||
| 1067 | 78 | private function fetch_assoc() |
|
| 1068 | { |
||
| 1069 | 78 | if ($this->_result instanceof \Doctrine\DBAL\Statement) { |
|
| 1070 | if ( |
||
| 1071 | $this->doctrinePdoStmt |
||
| 1072 | && |
||
| 1073 | $this->doctrinePdoStmt instanceof \Doctrine\DBAL\Driver\PDOStatement |
||
| 1074 | ) { |
||
| 1075 | if ($this->doctrinePdoStmtDataSeekInit === false) { |
||
| 1076 | $this->doctrinePdoStmtDataSeekInit = true; |
||
| 1077 | |||
| 1078 | $this->doctrinePdoStmtDataSeekFakeCache = $this->_result->fetchAll(\Doctrine\DBAL\FetchMode::ASSOCIATIVE); |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | $return = ($this->doctrinePdoStmtDataSeekFakeCache[$this->doctrinePdoStmtDataSeekFake] ?? null); |
||
| 1082 | |||
| 1083 | $this->doctrinePdoStmtDataSeekFake++; |
||
| 1084 | |||
| 1085 | return $return; |
||
| 1086 | } |
||
| 1087 | |||
| 1088 | if ( |
||
| 1089 | $this->doctrineMySQLiStmt |
||
| 1090 | && |
||
| 1091 | $this->doctrineMySQLiStmt instanceof \mysqli_stmt |
||
| 1092 | ) { |
||
| 1093 | return $this->_result->fetch( |
||
| 1094 | \Doctrine\DBAL\FetchMode::ASSOCIATIVE, |
||
| 1095 | 0 // FETCH_ORI_NEXT |
||
| 1096 | ); |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | return null; |
||
| 1100 | } |
||
| 1101 | |||
| 1102 | 78 | return \mysqli_fetch_assoc($this->_result); |
|
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * @return array|bool |
||
| 1107 | */ |
||
| 1108 | 1 | private function fetch_fields() |
|
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Returns the first row element from the result. |
||
| 1155 | * |
||
| 1156 | * @param string $column The column name to use as value (optional) |
||
| 1157 | * |
||
| 1158 | * @return mixed A row array or a single scalar value |
||
| 1159 | */ |
||
| 1160 | 3 | public function first(string $column = null) |
|
| 1168 | |||
| 1169 | /** |
||
| 1170 | * free the memory |
||
| 1171 | */ |
||
| 1172 | 100 | public function free() |
|
| 1201 | |||
| 1202 | /** |
||
| 1203 | * alias for "Result->fetch()" |
||
| 1204 | * |
||
| 1205 | * @see Result::fetch() |
||
| 1206 | * |
||
| 1207 | * @return array|false|object <p><strong>false</strong> on error</p> |
||
| 1208 | */ |
||
| 1209 | 3 | public function get() |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * alias for "Result->fetchAll()" |
||
| 1216 | * |
||
| 1217 | * @see Result::fetchAll() |
||
| 1218 | * |
||
| 1219 | * @return array |
||
| 1220 | */ |
||
| 1221 | 3 | public function getAll(): array |
|
| 1225 | |||
| 1226 | /** |
||
| 1227 | * alias for "Result->fetchAllColumn()" |
||
| 1228 | * |
||
| 1229 | * @see Result::fetchAllColumn() |
||
| 1230 | * |
||
| 1231 | * @param string $column |
||
| 1232 | * @param bool $skipNullValues |
||
| 1233 | * |
||
| 1234 | * @return array |
||
| 1235 | */ |
||
| 1236 | public function getAllColumn(string $column, bool $skipNullValues = false): array |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * alias for "Result->fetchAllArray()" |
||
| 1243 | * |
||
| 1244 | * @see Result::fetchAllArray() |
||
| 1245 | * |
||
| 1246 | * @return array |
||
| 1247 | */ |
||
| 1248 | 3 | public function getArray(): array |
|
| 1252 | |||
| 1253 | /** |
||
| 1254 | * alias for "Result->fetchAllArrayy()" |
||
| 1255 | * |
||
| 1256 | * @see Result::fetchAllArrayy() |
||
| 1257 | * |
||
| 1258 | * @return Arrayy |
||
| 1259 | */ |
||
| 1260 | public function getArrayy(): Arrayy |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * alias for "Result->fetchColumn()" |
||
| 1267 | * |
||
| 1268 | * @see Result::fetchColumn() |
||
| 1269 | * |
||
| 1270 | * @param string $column |
||
| 1271 | * @param bool $asArray |
||
| 1272 | * @param bool $skipNullValues |
||
| 1273 | * |
||
| 1274 | * @return array|string <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 1275 | * "$asArray"</p> |
||
| 1276 | */ |
||
| 1277 | 3 | public function getColumn(string $column, bool $skipNullValues = true, bool $asArray = false) |
|
| 1281 | |||
| 1282 | /** |
||
| 1283 | * @return string |
||
| 1284 | */ |
||
| 1285 | 3 | public function getDefaultResultType(): string |
|
| 1289 | |||
| 1290 | /** |
||
| 1291 | * alias for "Result->fetchAllObject()" |
||
| 1292 | * |
||
| 1293 | * @see Result::fetchAllObject() |
||
| 1294 | * |
||
| 1295 | * @return array of mysql-objects |
||
| 1296 | */ |
||
| 1297 | 3 | public function getObject(): array |
|
| 1301 | |||
| 1302 | /** |
||
| 1303 | * alias for "Result->fetchAllYield()" |
||
| 1304 | * |
||
| 1305 | * @see Result::fetchAllYield() |
||
| 1306 | * |
||
| 1307 | * @param bool $asArray |
||
| 1308 | * |
||
| 1309 | * @return \Generator |
||
| 1310 | */ |
||
| 1311 | 1 | public function getYield($asArray = false): \Generator |
|
| 1315 | |||
| 1316 | /** |
||
| 1317 | * Check if the result is empty. |
||
| 1318 | * |
||
| 1319 | * @return bool |
||
| 1320 | */ |
||
| 1321 | 41 | public function is_empty(): bool |
|
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Fetch all results as "json"-string. |
||
| 1328 | * |
||
| 1329 | * @return string |
||
| 1330 | */ |
||
| 1331 | 3 | public function json(): string |
|
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Returns the last row element from the result. |
||
| 1340 | * |
||
| 1341 | * @param string $column The column name to use as value (optional) |
||
| 1342 | * |
||
| 1343 | * @return mixed A row array or a single scalar value |
||
| 1344 | */ |
||
| 1345 | 3 | public function last(string $column = null) |
|
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Set the mapper... |
||
| 1356 | * |
||
| 1357 | * @param \Closure $callable |
||
| 1358 | * |
||
| 1359 | * @return $this |
||
| 1360 | */ |
||
| 1361 | 1 | public function map(\Closure $callable): self |
|
| 1367 | |||
| 1368 | /** |
||
| 1369 | * Alias of count(). Deprecated. |
||
| 1370 | * |
||
| 1371 | * @return int The number of rows in the result |
||
| 1372 | */ |
||
| 1373 | 1 | public function num_rows(): int |
|
| 1377 | |||
| 1378 | /** |
||
| 1379 | * ArrayAccess interface implementation. |
||
| 1380 | * |
||
| 1381 | * @param int $offset <p>Offset number</p> |
||
| 1382 | * |
||
| 1383 | * @return bool <p>true if offset exists, false otherwise</p> |
||
| 1384 | */ |
||
| 1385 | 1 | public function offsetExists($offset): bool |
|
| 1389 | |||
| 1390 | /** |
||
| 1391 | * ArrayAccess interface implementation. |
||
| 1392 | * |
||
| 1393 | * @param int $offset Offset number |
||
| 1394 | * |
||
| 1395 | * @return mixed |
||
| 1396 | */ |
||
| 1397 | 1 | public function offsetGet($offset) |
|
| 1405 | |||
| 1406 | /** |
||
| 1407 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1408 | * |
||
| 1409 | * @param mixed $offset |
||
| 1410 | * @param mixed $value |
||
| 1411 | */ |
||
| 1412 | public function offsetSet($offset, $value) |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1419 | * |
||
| 1420 | * @param mixed $offset |
||
| 1421 | */ |
||
| 1422 | public function offsetUnset($offset) |
||
| 1426 | |||
| 1427 | /** |
||
| 1428 | * Reset the offset (data_seek) for the results. |
||
| 1429 | * |
||
| 1430 | * @return Result |
||
| 1431 | */ |
||
| 1432 | public function reset(): self |
||
| 1456 | |||
| 1457 | /** |
||
| 1458 | * You can set the default result-type to Result::RESULT_TYPE_*. |
||
| 1459 | * |
||
| 1460 | * INFO: used for "fetch()" and "fetchAll()" |
||
| 1461 | * |
||
| 1462 | * @param string $default_result_type |
||
| 1463 | */ |
||
| 1464 | public function setDefaultResultType(string $default_result_type = self::RESULT_TYPE_OBJECT) |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * @param int $offset |
||
| 1481 | * @param int|null $length |
||
| 1482 | * @param bool $preserve_keys |
||
| 1483 | * |
||
| 1484 | * @return array |
||
| 1485 | */ |
||
| 1486 | public function slice(int $offset = 0, int $length = null, bool $preserve_keys = false): array |
||
| 1512 | } |
||
| 1513 |
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: