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 bool |
||
| 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) |
|
| 180 | |||
| 181 | 101 | /** |
|
| 182 | * __destruct |
||
| 183 | */ |
||
| 184 | 101 | public function __destruct() |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Runs a user-provided callback with the MySQLi_Result object given as |
||
| 191 | * argument and returns the result, or returns the MySQLi_Result object if |
||
| 192 | 100 | * called without an argument. |
|
| 193 | * |
||
| 194 | 100 | * @param callable $callback User-provided callback (optional) |
|
| 195 | 100 | * |
|
| 196 | * @return \Doctrine\DBAL\Statement|mixed|\mysqli_result |
||
| 197 | */ |
||
| 198 | public function __invoke(callable $callback = null) |
||
| 206 | 2 | ||
| 207 | /** |
||
| 208 | 2 | * Get the current "num_rows" as string. |
|
| 209 | 2 | * |
|
| 210 | * @return string |
||
| 211 | */ |
||
| 212 | 1 | public function __toString() |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Cast data into int, float or string. |
||
| 219 | * |
||
| 220 | * <p> |
||
| 221 | * <br /> |
||
| 222 | * INFO: install / use "mysqlnd"-driver for better performance |
||
| 223 | * </p> |
||
| 224 | * |
||
| 225 | * @param array|object $data |
||
| 226 | * |
||
| 227 | * @return array|false|object |
||
| 228 | * <p><strong>false</strong> on error</p> |
||
| 229 | */ |
||
| 230 | private function cast(&$data) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Countable interface implementation. |
||
| 307 | * |
||
| 308 | * @return int The number of rows in the result |
||
| 309 | */ |
||
| 310 | public function count(): int |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Iterator interface implementation. |
||
| 317 | 2 | * |
|
| 318 | * @return mixed The current element |
||
| 319 | 2 | */ |
|
| 320 | public function current() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Iterator interface implementation. |
||
| 327 | 8 | * |
|
| 328 | * @return int The current element key (row index; zero-based) |
||
| 329 | 8 | */ |
|
| 330 | public function key(): int |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Iterator interface implementation. |
||
| 337 | 1 | * |
|
| 338 | * @return void |
||
| 339 | 1 | */ |
|
| 340 | public function next() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Iterator interface implementation. |
||
| 347 | 8 | * |
|
| 348 | * @param int $row Row position to rewind to; defaults to 0 |
||
| 349 | 8 | * |
|
| 350 | 8 | * @return void |
|
| 351 | */ |
||
| 352 | public function rewind($row = 0) |
||
| 358 | |||
| 359 | 12 | /** |
|
| 360 | * Moves the internal pointer to the specified row position. |
||
| 361 | 12 | * |
|
| 362 | 10 | * @param int $row <p>Row position; zero-based and set to 0 by default</p> |
|
| 363 | * |
||
| 364 | 12 | * @return bool |
|
| 365 | * <p>true on success, false otherwise</p> |
||
| 366 | */ |
||
| 367 | public function seek($row = 0): bool |
||
| 395 | |||
| 396 | /** |
||
| 397 | 4 | * Iterator interface implementation. |
|
| 398 | * |
||
| 399 | * @return bool |
||
| 400 | * <p>true if the current index is valid, false otherwise</p> |
||
| 401 | */ |
||
| 402 | public function valid(): bool |
||
| 406 | |||
| 407 | 8 | /** |
|
| 408 | * Fetch. |
||
| 409 | * |
||
| 410 | * <p> |
||
| 411 | * <br /> |
||
| 412 | * INFO: this will return an object by default, not an array<br /> |
||
| 413 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 414 | * </p> |
||
| 415 | * |
||
| 416 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 417 | * |
||
| 418 | * @return array|false|object |
||
| 419 | * <p><strong>false</strong> on error</p> |
||
| 420 | */ |
||
| 421 | public function fetch(bool $reset = false) |
||
| 437 | 6 | ||
| 438 | /** |
||
| 439 | * Fetch all results. |
||
| 440 | * |
||
| 441 | * <p> |
||
| 442 | * <br /> |
||
| 443 | * INFO: this will return an object by default, not an array<br /> |
||
| 444 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 445 | * </p> |
||
| 446 | * |
||
| 447 | * @return array |
||
| 448 | */ |
||
| 449 | public function fetchAll(): array |
||
| 465 | 6 | ||
| 466 | /** |
||
| 467 | * Fetch all results as array. |
||
| 468 | * |
||
| 469 | * @return array |
||
| 470 | */ |
||
| 471 | public function fetchAllArray(): array |
||
| 487 | 28 | ||
| 488 | /** |
||
| 489 | * Fetch all results as "Arrayy"-object. |
||
| 490 | * |
||
| 491 | * @return Arrayy |
||
| 492 | */ |
||
| 493 | public function fetchAllArrayy(): Arrayy |
||
| 509 | 10 | ||
| 510 | /** |
||
| 511 | * Fetch all results as "Arrayy"-object. |
||
| 512 | * |
||
| 513 | * @return Arrayy |
||
| 514 | */ |
||
| 515 | public function fetchAllArrayyYield(): Arrayy |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Fetch a single column as an 1-dimension array. |
||
| 535 | * |
||
| 536 | * @param string $column |
||
| 537 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: false</p> |
||
| 538 | * |
||
| 539 | * @return array |
||
| 540 | * <p>Return an empty array if the "$column" wasn't found</p> |
||
| 541 | 9 | */ |
|
| 542 | public function fetchAllColumn(string $column, bool $skipNullValues = false): array |
||
| 550 | 9 | ||
| 551 | /** |
||
| 552 | * Fetch all results as array with objects. |
||
| 553 | * |
||
| 554 | 9 | * @param object|string $class <p> |
|
| 555 | 9 | * <strong>string</strong>: create a new object (with optional constructor |
|
| 556 | * parameter)<br> |
||
| 557 | 9 | * <strong>object</strong>: use a object and fill the the data into |
|
| 558 | * </p> |
||
| 559 | 9 | * @param array|null $params optional |
|
| 560 | 3 | * <p> |
|
| 561 | 3 | * An array of parameters to pass to the constructor, used if $class is a |
|
| 562 | * string. |
||
| 563 | 9 | * </p> |
|
| 564 | * |
||
| 565 | * @return array |
||
| 566 | 9 | */ |
|
| 567 | public function fetchAllObject($class = '', array $params = null): array |
||
| 611 | |||
| 612 | 8 | /** |
|
| 613 | * Fetch all results as "\Generator" via yield. |
||
| 614 | * |
||
| 615 | 8 | * @param object|string $class <p> |
|
| 616 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 617 | 8 | * parameter)<br> |
|
| 618 | * <strong>object</strong>: use a object and fill the the data into |
||
| 619 | * </p> |
||
| 620 | * @param array|null $params optional |
||
| 621 | 8 | * <p> |
|
| 622 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 623 | * string. |
||
| 624 | 8 | * </p> |
|
| 625 | * |
||
| 626 | 8 | * @return \Generator |
|
| 627 | 8 | */ |
|
| 628 | 8 | public function fetchAllYield($class = '', array $params = null): \Generator |
|
| 670 | |||
| 671 | /** |
||
| 672 | * Fetch as array. |
||
| 673 | * |
||
| 674 | * @param bool $reset |
||
| 675 | * |
||
| 676 | * @return array|false |
||
| 677 | * <p><strong>false</strong> on error</p> |
||
| 678 | */ |
||
| 679 | public function fetchArray(bool $reset = false) |
||
| 700 | 3 | ||
| 701 | /** |
||
| 702 | * Fetch data as a key/value pair array. |
||
| 703 | * |
||
| 704 | 3 | * <p> |
|
| 705 | * <br /> |
||
| 706 | * INFO: both "key" and "value" must exists in the fetched data |
||
| 707 | * the key will be the new key of the result-array |
||
| 708 | * <br /><br /> |
||
| 709 | * </p> |
||
| 710 | * |
||
| 711 | * e.g.: |
||
| 712 | * <code> |
||
| 713 | * fetchArrayPair('some_id', 'some_value'); |
||
| 714 | 6 | * // array(127 => 'some value', 128 => 'some other value') |
|
| 715 | * </code> |
||
| 716 | 6 | * |
|
| 717 | * @param string $key |
||
| 718 | * @param string $value |
||
| 719 | * |
||
| 720 | 6 | * @return array |
|
| 721 | 6 | */ |
|
| 722 | 3 | public function fetchArrayPair(string $key, string $value): array |
|
| 741 | 17 | ||
| 742 | /** |
||
| 743 | 17 | * Fetch as "Arrayy"-object. |
|
| 744 | 2 | * |
|
| 745 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 746 | * |
||
| 747 | 15 | * @return Arrayy|false |
|
| 748 | 14 | * <p><strong>false</strong> on error</p> |
|
| 749 | */ |
||
| 750 | public function fetchArrayy(bool $reset = false) |
||
| 767 | |||
| 768 | /** |
||
| 769 | 14 | * Fetches a row or a single column within a row. Returns null if there are |
|
| 770 | * no more rows in the result. |
||
| 771 | * |
||
| 772 | * @param int $row The row number (optional) |
||
| 773 | * @param string $column The column name (optional) |
||
| 774 | * |
||
| 775 | * @return mixed An associative array or a scalar value |
||
| 776 | */ |
||
| 777 | public function fetchCallable(int $row = null, string $column = null) |
||
| 807 | 5 | ||
| 808 | /** |
||
| 809 | 5 | * Fetch a single column as string (or as 1-dimension array). |
|
| 810 | 5 | * |
|
| 811 | 3 | * @param string $column |
|
| 812 | 3 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: true</p> |
|
| 813 | * @param bool $asArray <p>Get all values and not only the last one. | default: false</p> |
||
| 814 | 5 | * |
|
| 815 | 3 | * @return array|string |
|
| 816 | * <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 817 | * "$asArray"</p> |
||
| 818 | 5 | */ |
|
| 819 | public function fetchColumn( |
||
| 863 | |||
| 864 | 1 | /** |
|
| 865 | 1 | * Return rows of field information in a result set. |
|
| 866 | * |
||
| 867 | * @param bool $as_array Return each field info as array; defaults to false |
||
| 868 | * |
||
| 869 | 1 | * @return array |
|
| 870 | * <p>Array of field information each as an associative array.</p> |
||
| 871 | 1 | */ |
|
| 872 | public function fetchFields(bool $as_array = false): array |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Returns all rows at once as a grouped array of scalar values or arrays. |
||
| 893 | * |
||
| 894 | * @param string $group The column name to use for grouping |
||
| 895 | * @param string $column The column name to use as values (optional) |
||
| 896 | * |
||
| 897 | 21 | * @return array |
|
| 898 | * <p>A grouped array of scalar values or arrays.</p> |
||
| 899 | 21 | */ |
|
| 900 | 9 | View Code Duplication | public function fetchGroups(string $group, string $column = null): array |
| 926 | 21 | ||
| 927 | 21 | /** |
|
| 928 | 21 | * Fetch as object. |
|
| 929 | * |
||
| 930 | 21 | * @param object|string $class <p> |
|
| 931 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 932 | * parameter)<br> |
||
| 933 | * <strong>object</strong>: use a object and fill the the data into |
||
| 934 | 21 | * </p> |
|
| 935 | * @param array|null $params optional |
||
| 936 | * <p> |
||
| 937 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 938 | * string. |
||
| 939 | * </p> |
||
| 940 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 941 | * |
||
| 942 | * @return false|object |
||
| 943 | * <p><strong>false</strong> on error</p> |
||
| 944 | */ |
||
| 945 | 1 | View Code Duplication | public function fetchObject($class = '', array $params = null, bool $reset = false) |
| 983 | 1 | ||
| 984 | 1 | /** |
|
| 985 | 1 | * Returns all rows at once as key-value pairs. |
|
| 986 | * |
||
| 987 | 1 | * @param string $key The column name to use as keys |
|
| 988 | 1 | * @param string $column The column name to use as values (optional) |
|
| 989 | 1 | * |
|
| 990 | * @return array |
||
| 991 | * <p>An array of key-value pairs.</p> |
||
| 992 | */ |
||
| 993 | 1 | View Code Duplication | public function fetchPairs(string $key, string $column = null): array |
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Returns all rows at once, transposed as an array of arrays. Instead of |
||
| 1022 | * returning rows of columns, this method returns columns of rows. |
||
| 1023 | * |
||
| 1024 | 4 | * @param string $column The column name to use as keys (optional) |
|
| 1025 | * |
||
| 1026 | 4 | * @return array |
|
| 1027 | * <p>A transposed array of arrays</p> |
||
| 1028 | */ |
||
| 1029 | public function fetchTranspose(string $column = null) |
||
| 1055 | 3 | ||
| 1056 | /** |
||
| 1057 | 4 | * Fetch as "\Generator" via yield. |
|
| 1058 | * |
||
| 1059 | * @param object|string $class <p> |
||
| 1060 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 1061 | 4 | * parameter)<br> |
|
| 1062 | 4 | * <strong>object</strong>: use a object and fill the the data into |
|
| 1063 | * </p> |
||
| 1064 | * @param array|null $params optional |
||
| 1065 | * <p> |
||
| 1066 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 1067 | 78 | * string. |
|
| 1068 | * </p> |
||
| 1069 | 78 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
|
| 1070 | * |
||
| 1071 | * @return \Generator |
||
| 1072 | */ |
||
| 1073 | View Code Duplication | public function fetchYield($class = '', array $params = null, bool $reset = false): \Generator |
|
| 1111 | 1 | ||
| 1112 | /** |
||
| 1113 | * @return mixed|null |
||
| 1114 | */ |
||
| 1115 | private function fetch_assoc() |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * @return array|false |
||
| 1155 | */ |
||
| 1156 | private function fetch_fields() |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Returns the first row element from the result. |
||
| 1206 | * |
||
| 1207 | * @param string $column The column name to use as value (optional) |
||
| 1208 | * |
||
| 1209 | 3 | * @return mixed |
|
| 1210 | * <p>A row array or a single scalar value</p> |
||
| 1211 | 3 | */ |
|
| 1212 | public function first(string $column = null) |
||
| 1220 | |||
| 1221 | 3 | /** |
|
| 1222 | * free the memory |
||
| 1223 | 3 | */ |
|
| 1224 | public function free() |
||
| 1245 | |||
| 1246 | /** |
||
| 1247 | * alias for "Result->fetch()" |
||
| 1248 | 3 | * |
|
| 1249 | * @return array|false|object |
||
| 1250 | 3 | * <p><strong>false</strong> on error</p> |
|
| 1251 | * |
||
| 1252 | * @see Result::fetch() |
||
| 1253 | */ |
||
| 1254 | public function get() |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * alias for "Result->fetchAll()" |
||
| 1261 | * |
||
| 1262 | * @return array |
||
| 1263 | * |
||
| 1264 | * @see Result::fetchAll() |
||
| 1265 | */ |
||
| 1266 | public function getAll(): array |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * alias for "Result->fetchAllColumn()" |
||
| 1273 | * |
||
| 1274 | * @param string $column |
||
| 1275 | * @param bool $skipNullValues |
||
| 1276 | * |
||
| 1277 | 3 | * @return array |
|
| 1278 | * |
||
| 1279 | 3 | * @see Result::fetchAllColumn() |
|
| 1280 | */ |
||
| 1281 | public function getAllColumn(string $column, bool $skipNullValues = false): array |
||
| 1285 | 3 | ||
| 1286 | /** |
||
| 1287 | 3 | * alias for "Result->fetchAllArray()" |
|
| 1288 | * |
||
| 1289 | * @return array |
||
| 1290 | * |
||
| 1291 | * @see Result::fetchAllArray() |
||
| 1292 | */ |
||
| 1293 | public function getArray(): array |
||
| 1297 | 3 | ||
| 1298 | /** |
||
| 1299 | 3 | * alias for "Result->fetchAllArrayy()" |
|
| 1300 | * |
||
| 1301 | * @return Arrayy |
||
| 1302 | * |
||
| 1303 | * @see Result::fetchAllArrayy() |
||
| 1304 | */ |
||
| 1305 | public function getArrayy(): Arrayy |
||
| 1309 | |||
| 1310 | /** |
||
| 1311 | 1 | * alias for "Result->fetchColumn()" |
|
| 1312 | * |
||
| 1313 | 1 | * @param string $column |
|
| 1314 | * @param bool $asArray |
||
| 1315 | * @param bool $skipNullValues |
||
| 1316 | * |
||
| 1317 | * @return array|string |
||
| 1318 | * <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 1319 | * "$asArray"</p> |
||
| 1320 | * |
||
| 1321 | 41 | * @see Result::fetchColumn() |
|
| 1322 | */ |
||
| 1323 | 41 | public function getColumn( |
|
| 1330 | |||
| 1331 | 3 | /** |
|
| 1332 | * @return string |
||
| 1333 | 3 | */ |
|
| 1334 | public function getDefaultResultType(): string |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * alias for "Result->fetchAllObject()" |
||
| 1341 | * |
||
| 1342 | * @return array of mysql-objects |
||
| 1343 | * |
||
| 1344 | * @see Result::fetchAllObject() |
||
| 1345 | 3 | */ |
|
| 1346 | public function getObject(): array |
||
| 1350 | |||
| 1351 | 3 | /** |
|
| 1352 | * alias for "Result->fetchAllYield()" |
||
| 1353 | * |
||
| 1354 | * @return \Generator |
||
| 1355 | * |
||
| 1356 | * @see Result::fetchAllYield() |
||
| 1357 | */ |
||
| 1358 | public function getYield(): \Generator |
||
| 1362 | |||
| 1363 | 1 | /** |
|
| 1364 | * Check if the result is empty. |
||
| 1365 | 1 | * |
|
| 1366 | * @return bool |
||
| 1367 | */ |
||
| 1368 | public function is_empty(): bool |
||
| 1372 | |||
| 1373 | 1 | /** |
|
| 1374 | * Fetch all results as "json"-string. |
||
| 1375 | 1 | * |
|
| 1376 | * @return false|string |
||
| 1377 | */ |
||
| 1378 | public function json() |
||
| 1384 | |||
| 1385 | 1 | /** |
|
| 1386 | * Returns the last row element from the result. |
||
| 1387 | 1 | * |
|
| 1388 | * @param string $column The column name to use as value (optional) |
||
| 1389 | * |
||
| 1390 | * @return mixed A row array or a single scalar value |
||
| 1391 | */ |
||
| 1392 | public function last(string $column = null) |
||
| 1400 | 1 | ||
| 1401 | /** |
||
| 1402 | * Set the mapper... |
||
| 1403 | * |
||
| 1404 | * @param \Closure $callable |
||
| 1405 | * |
||
| 1406 | * @return $this |
||
| 1407 | */ |
||
| 1408 | public function map(\Closure $callable): self |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Alias of count(). Deprecated. |
||
| 1417 | * |
||
| 1418 | * @return int |
||
| 1419 | * <p>The number of rows in the result.</p> |
||
| 1420 | */ |
||
| 1421 | public function num_rows(): int |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * ArrayAccess interface implementation. |
||
| 1428 | * |
||
| 1429 | * @param int $offset <p>Offset number</p> |
||
| 1430 | * |
||
| 1431 | * @return bool |
||
| 1432 | 38 | * <p>true if offset exists, false otherwise.</p> |
|
| 1433 | */ |
||
| 1434 | 38 | public function offsetExists($offset): bool |
|
| 1438 | 38 | ||
| 1439 | /** |
||
| 1440 | 38 | * ArrayAccess interface implementation. |
|
| 1441 | * |
||
| 1442 | * @param int $offset Offset number |
||
| 1443 | * |
||
| 1444 | * @return mixed |
||
| 1445 | */ |
||
| 1446 | 38 | public function offsetGet($offset) |
|
| 1454 | 38 | ||
| 1455 | /** |
||
| 1456 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1457 | * |
||
| 1458 | * @param mixed $offset |
||
| 1459 | * @param mixed $value |
||
| 1460 | */ |
||
| 1461 | public function offsetSet($offset, $value) |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | 6 | * ArrayAccess interface implementation. Not implemented by design. |
|
| 1468 | * |
||
| 1469 | 6 | * @param mixed $offset |
|
| 1470 | */ |
||
| 1471 | public function offsetUnset($offset) |
||
| 1475 | 6 | ||
| 1476 | /** |
||
| 1477 | 6 | * Reset the offset (data_seek) for the results. |
|
| 1478 | * |
||
| 1479 | * @return Result |
||
| 1480 | */ |
||
| 1481 | public function reset(): self |
||
| 1497 | |||
| 1498 | /** |
||
| 1499 | 1 | * You can set the default result-type to Result::RESULT_TYPE_*. |
|
| 1500 | 1 | * |
|
| 1501 | 1 | * INFO: used for "fetch()" and "fetchAll()" |
|
| 1502 | 1 | * |
|
| 1503 | 1 | * @param string $default_result_type |
|
| 1504 | */ |
||
| 1505 | 1 | public function setDefaultResultType(string $default_result_type = self::RESULT_TYPE_OBJECT) |
|
| 1519 | |||
| 1520 | /** |
||
| 1521 | * @param int $offset |
||
| 1522 | * @param int|null $length |
||
| 1523 | * @param bool $preserve_keys |
||
| 1524 | * |
||
| 1525 | * @return array |
||
| 1526 | */ |
||
| 1527 | public function slice(int $offset = 0, int $length = null, bool $preserve_keys = false): array |
||
| 1553 | } |
||
| 1554 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: