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 |
||
| 17 | final class Result implements \Countable, \SeekableIterator, \ArrayAccess |
||
| 18 | { |
||
| 19 | |||
| 20 | const MYSQL_TYPE_BIT = 16; |
||
| 21 | const MYSQL_TYPE_BLOB = 252; |
||
| 22 | const MYSQL_TYPE_DATE = 10; |
||
| 23 | const MYSQL_TYPE_DATETIME = 12; |
||
| 24 | const MYSQL_TYPE_DECIMAL = 0; |
||
| 25 | const MYSQL_TYPE_DOUBLE = 5; |
||
| 26 | const MYSQL_TYPE_ENUM = 247; |
||
| 27 | const MYSQL_TYPE_FLOAT = 4; |
||
| 28 | const MYSQL_TYPE_GEOMETRY = 255; |
||
| 29 | const MYSQL_TYPE_INT24 = 9; |
||
| 30 | const MYSQL_TYPE_JSON = 245; |
||
| 31 | const MYSQL_TYPE_LONG = 3; |
||
| 32 | const MYSQL_TYPE_LONGLONG = 8; |
||
| 33 | const MYSQL_TYPE_LONG_BLOB = 251; |
||
| 34 | const MYSQL_TYPE_MEDIUM_BLOB = 250; |
||
| 35 | const MYSQL_TYPE_NEWDATE = 14; |
||
| 36 | const MYSQL_TYPE_NEWDECIMAL = 246; |
||
| 37 | const MYSQL_TYPE_NULL = 6; |
||
| 38 | const MYSQL_TYPE_SET = 248; |
||
| 39 | const MYSQL_TYPE_SHORT = 2; |
||
| 40 | const MYSQL_TYPE_STRING = 254; |
||
| 41 | const MYSQL_TYPE_TIME = 11; |
||
| 42 | const MYSQL_TYPE_TIMESTAMP = 7; |
||
| 43 | const MYSQL_TYPE_TINY = 1; |
||
| 44 | const MYSQL_TYPE_TINY_BLOB = 249; |
||
| 45 | const MYSQL_TYPE_VARCHAR = 15; |
||
| 46 | const MYSQL_TYPE_VAR_STRING = 253; |
||
| 47 | const MYSQL_TYPE_YEAR = 13; |
||
| 48 | |||
| 49 | const RESULT_TYPE_ARRAY = 'array'; |
||
| 50 | const RESULT_TYPE_ARRAYY = 'Arrayy'; |
||
| 51 | const RESULT_TYPE_OBJECT = 'object'; |
||
| 52 | const RESULT_TYPE_YIELD = 'yield'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | public $num_rows; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | public $sql; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var \mysqli_result|\Doctrine\DBAL\Statement |
||
| 66 | */ |
||
| 67 | private $_result; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var int |
||
| 71 | */ |
||
| 72 | private $current_row; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var \Closure|null |
||
| 76 | */ |
||
| 77 | private $_mapper; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | private $_default_result_type = self::RESULT_TYPE_OBJECT; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var \mysqli_stmt|null |
||
| 86 | */ |
||
| 87 | private $doctrineMySQLiStmt; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var \Doctrine\DBAL\Driver\PDOStatement|null |
||
| 91 | */ |
||
| 92 | private $doctrinePdoStmt; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Result constructor. |
||
| 96 | * |
||
| 97 | * @param string $sql |
||
| 98 | * @param \mysqli_result $result |
||
| 99 | * @param \Closure $mapper Optional callback mapper for the "fetchCallable()" method |
||
| 100 | */ |
||
| 101 | 91 | public function __construct(string $sql, $result, \Closure $mapper = null) |
|
| 139 | |||
| 140 | /** |
||
| 141 | * __destruct |
||
| 142 | */ |
||
| 143 | 90 | public function __destruct() |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Runs a user-provided callback with the MySQLi_Result object given as |
||
| 150 | * argument and returns the result, or returns the MySQLi_Result object if |
||
| 151 | * called without an argument. |
||
| 152 | * |
||
| 153 | * @param callable $callback User-provided callback (optional) |
||
| 154 | * |
||
| 155 | * @return mixed|\Doctrine\DBAL\Statement|\mysqli_result |
||
| 156 | */ |
||
| 157 | 2 | public function __invoke(callable $callback = null) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Get the current "num_rows" as string. |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | public function __toString() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Cast data into int, float or string. |
||
| 178 | * |
||
| 179 | * <p> |
||
| 180 | * <br /> |
||
| 181 | * INFO: install / use "mysqlnd"-driver for better performance |
||
| 182 | * </p> |
||
| 183 | * |
||
| 184 | * @param array|object $data |
||
| 185 | * |
||
| 186 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 187 | */ |
||
| 188 | 64 | private function cast(&$data) |
|
| 258 | |||
| 259 | /** |
||
| 260 | * Countable interface implementation. |
||
| 261 | * |
||
| 262 | * @return int The number of rows in the result |
||
| 263 | */ |
||
| 264 | 2 | public function count(): int |
|
| 268 | |||
| 269 | /** |
||
| 270 | * Iterator interface implementation. |
||
| 271 | * |
||
| 272 | * @return mixed The current element |
||
| 273 | */ |
||
| 274 | 7 | public function current() |
|
| 278 | |||
| 279 | /** |
||
| 280 | * Iterator interface implementation. |
||
| 281 | * |
||
| 282 | * @return int The current element key (row index; zero-based) |
||
| 283 | */ |
||
| 284 | 1 | public function key(): int |
|
| 288 | |||
| 289 | /** |
||
| 290 | * Iterator interface implementation. |
||
| 291 | * |
||
| 292 | * @return void |
||
| 293 | */ |
||
| 294 | 7 | public function next() |
|
| 298 | |||
| 299 | /** |
||
| 300 | * Iterator interface implementation. |
||
| 301 | * |
||
| 302 | * @param int $row Row position to rewind to; defaults to 0 |
||
| 303 | * |
||
| 304 | * @return void |
||
| 305 | */ |
||
| 306 | 11 | public function rewind($row = 0) |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Moves the internal pointer to the specified row position. |
||
| 315 | * |
||
| 316 | * @param int $row <p>Row position; zero-based and set to 0 by default</p> |
||
| 317 | * |
||
| 318 | * @return bool <p>true on success, false otherwise</p> |
||
| 319 | */ |
||
| 320 | 19 | public function seek($row = 0): bool |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Iterator interface implementation. |
||
| 342 | * |
||
| 343 | * @return bool <p>true if the current index is valid, false otherwise</p> |
||
| 344 | */ |
||
| 345 | 7 | public function valid(): bool |
|
| 349 | |||
| 350 | /** |
||
| 351 | * Fetch. |
||
| 352 | * |
||
| 353 | * <p> |
||
| 354 | * <br /> |
||
| 355 | * INFO: this will return an object by default, not an array<br /> |
||
| 356 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 357 | * </p> |
||
| 358 | * |
||
| 359 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 360 | * |
||
| 361 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 362 | */ |
||
| 363 | 4 | public function fetch(bool $reset = false) |
|
| 379 | |||
| 380 | /** |
||
| 381 | * Fetch all results. |
||
| 382 | * |
||
| 383 | * <p> |
||
| 384 | * <br /> |
||
| 385 | * INFO: this will return an object by default, not an array<br /> |
||
| 386 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 387 | * </p> |
||
| 388 | * |
||
| 389 | * @return array |
||
| 390 | */ |
||
| 391 | 4 | public function fetchAll(): array |
|
| 407 | |||
| 408 | /** |
||
| 409 | * Fetch all results as array. |
||
| 410 | * |
||
| 411 | * @return array |
||
| 412 | */ |
||
| 413 | 23 | public function fetchAllArray(): array |
|
| 429 | |||
| 430 | /** |
||
| 431 | * Fetch all results as "Arrayy"-object. |
||
| 432 | * |
||
| 433 | * @return Arrayy |
||
| 434 | */ |
||
| 435 | 7 | public function fetchAllArrayy(): Arrayy |
|
| 451 | |||
| 452 | /** |
||
| 453 | * Fetch a single column as an 1-dimension array. |
||
| 454 | * |
||
| 455 | * @param string $column |
||
| 456 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: false</p> |
||
| 457 | * |
||
| 458 | * @return array <p>Return an empty array if the "$column" wasn't found</p> |
||
| 459 | */ |
||
| 460 | 4 | public function fetchAllColumn(string $column, bool $skipNullValues = false): array |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Fetch all results as array with objects. |
||
| 467 | * |
||
| 468 | * @param object|string $class <p> |
||
| 469 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 470 | * parameter)<br> |
||
| 471 | * <strong>object</strong>: use a object and fill the the data into |
||
| 472 | * </p> |
||
| 473 | * @param null|array $params optional |
||
| 474 | * <p> |
||
| 475 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 476 | * string. |
||
| 477 | * </p> |
||
| 478 | * |
||
| 479 | * @return array |
||
| 480 | */ |
||
| 481 | 14 | public function fetchAllObject($class = '', array $params = null): array |
|
| 545 | |||
| 546 | /** |
||
| 547 | * Fetch all results as "\Generator" via yield. |
||
| 548 | * |
||
| 549 | * @param object|string $class <p> |
||
| 550 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 551 | * parameter)<br> |
||
| 552 | * <strong>object</strong>: use a object and fill the the data into |
||
| 553 | * </p> |
||
| 554 | * @param null|array $params optional |
||
| 555 | * <p> |
||
| 556 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 557 | * string. |
||
| 558 | * </p> |
||
| 559 | * |
||
| 560 | * @return \Generator |
||
| 561 | */ |
||
| 562 | 2 | public function fetchAllYield($class = '', array $params = null): \Generator |
|
| 625 | |||
| 626 | /** |
||
| 627 | * Fetch as array. |
||
| 628 | * |
||
| 629 | * @param bool $reset |
||
| 630 | * |
||
| 631 | * @return array|false <p><strong>false</strong> on error</p> |
||
| 632 | */ |
||
| 633 | 23 | View Code Duplication | public function fetchArray(bool $reset = false) |
| 650 | |||
| 651 | /** |
||
| 652 | * Fetch data as a key/value pair array. |
||
| 653 | * |
||
| 654 | * <p> |
||
| 655 | * <br /> |
||
| 656 | * INFO: both "key" and "value" must exists in the fetched data |
||
| 657 | * the key will be the new key of the result-array |
||
| 658 | * <br /><br /> |
||
| 659 | * </p> |
||
| 660 | * |
||
| 661 | * e.g.: |
||
| 662 | * <code> |
||
| 663 | * fetchArrayPair('some_id', 'some_value'); |
||
| 664 | * // array(127 => 'some value', 128 => 'some other value') |
||
| 665 | * </code> |
||
| 666 | * |
||
| 667 | * @param string $key |
||
| 668 | * @param string $value |
||
| 669 | * |
||
| 670 | * @return array |
||
| 671 | */ |
||
| 672 | 2 | public function fetchArrayPair(string $key, string $value): array |
|
| 691 | |||
| 692 | /** |
||
| 693 | * Fetch as "Arrayy"-object. |
||
| 694 | * |
||
| 695 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 696 | * |
||
| 697 | * @return Arrayy|false <p><strong>false</strong> on error</p> |
||
| 698 | */ |
||
| 699 | 4 | View Code Duplication | public function fetchArrayy(bool $reset = false) |
| 716 | |||
| 717 | /** |
||
| 718 | * Fetches a row or a single column within a row. Returns null if there are |
||
| 719 | * no more rows in the result. |
||
| 720 | * |
||
| 721 | * @param int $row The row number (optional) |
||
| 722 | * @param string $column The column name (optional) |
||
| 723 | * |
||
| 724 | * @return mixed An associative array or a scalar value |
||
| 725 | */ |
||
| 726 | 16 | public function fetchCallable(int $row = null, string $column = null) |
|
| 744 | |||
| 745 | /** |
||
| 746 | * Fetch a single column as string (or as 1-dimension array). |
||
| 747 | * |
||
| 748 | * @param string $column |
||
| 749 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: true</p> |
||
| 750 | * @param bool $asArray <p>Get all values and not only the last one. | default: false</p> |
||
| 751 | * |
||
| 752 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 753 | * "$asArray"</p> |
||
| 754 | */ |
||
| 755 | 7 | public function fetchColumn(string $column = '', bool $skipNullValues = true, bool $asArray = false) |
|
| 803 | |||
| 804 | /** |
||
| 805 | * Return rows of field information in a result set. |
||
| 806 | * |
||
| 807 | * @param bool $as_array Return each field info as array; defaults to false |
||
| 808 | * |
||
| 809 | * @return array Array of field information each as an associative array |
||
| 810 | */ |
||
| 811 | 1 | public function fetchFields(bool $as_array = false): array |
|
| 824 | |||
| 825 | /** |
||
| 826 | * Returns all rows at once as a grouped array of scalar values or arrays. |
||
| 827 | * |
||
| 828 | * @param string $group The column name to use for grouping |
||
| 829 | * @param string $column The column name to use as values (optional) |
||
| 830 | * |
||
| 831 | * @return array A grouped array of scalar values or arrays |
||
| 832 | */ |
||
| 833 | 1 | View Code Duplication | public function fetchGroups(string $group, string $column = null): array |
| 861 | |||
| 862 | /** |
||
| 863 | * Fetch as object. |
||
| 864 | * |
||
| 865 | * @param object|string $class <p> |
||
| 866 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 867 | * parameter)<br> |
||
| 868 | * <strong>object</strong>: use a object and fill the the data into |
||
| 869 | * </p> |
||
| 870 | * @param null|array $params optional |
||
| 871 | * <p> |
||
| 872 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 873 | * string. |
||
| 874 | * </p> |
||
| 875 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 876 | * |
||
| 877 | * @return object|false <p><strong>false</strong> on error</p> |
||
| 878 | */ |
||
| 879 | 25 | View Code Duplication | public function fetchObject($class = '', array $params = null, bool $reset = false) |
| 923 | |||
| 924 | /** |
||
| 925 | * Returns all rows at once as key-value pairs. |
||
| 926 | * |
||
| 927 | * @param string $key The column name to use as keys |
||
| 928 | * @param string $column The column name to use as values (optional) |
||
| 929 | * |
||
| 930 | * @return array An array of key-value pairs |
||
| 931 | */ |
||
| 932 | 1 | View Code Duplication | public function fetchPairs(string $key, string $column = null): array |
| 960 | |||
| 961 | /** |
||
| 962 | * Returns all rows at once, transposed as an array of arrays. Instead of |
||
| 963 | * returning rows of columns, this method returns columns of rows. |
||
| 964 | * |
||
| 965 | * @param string $column The column name to use as keys (optional) |
||
| 966 | * |
||
| 967 | * @return mixed A transposed array of arrays |
||
| 968 | */ |
||
| 969 | 1 | public function fetchTranspose(string $column = null) |
|
| 994 | |||
| 995 | /** |
||
| 996 | * Fetch as "\Generator" via yield. |
||
| 997 | * |
||
| 998 | * @param object|string $class <p> |
||
| 999 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 1000 | * parameter)<br> |
||
| 1001 | * <strong>object</strong>: use a object and fill the the data into |
||
| 1002 | * </p> |
||
| 1003 | * @param null|array $params optional |
||
| 1004 | * <p> |
||
| 1005 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 1006 | * string. |
||
| 1007 | * </p> |
||
| 1008 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 1009 | * |
||
| 1010 | * @return \Generator |
||
| 1011 | */ |
||
| 1012 | 2 | View Code Duplication | public function fetchYield($class = '', array $params = null, bool $reset = false): \Generator |
| 1058 | |||
| 1059 | /** |
||
| 1060 | * @return mixed |
||
| 1061 | */ |
||
| 1062 | 76 | private function fetch_assoc() |
|
| 1073 | |||
| 1074 | /** |
||
| 1075 | * @return array|bool |
||
| 1076 | */ |
||
| 1077 | 1 | private function fetch_fields() |
|
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Returns the first row element from the result. |
||
| 1124 | * |
||
| 1125 | * @param string $column The column name to use as value (optional) |
||
| 1126 | * |
||
| 1127 | * @return mixed A row array or a single scalar value |
||
| 1128 | */ |
||
| 1129 | 3 | public function first(string $column = null) |
|
| 1137 | |||
| 1138 | /** |
||
| 1139 | * free the memory |
||
| 1140 | */ |
||
| 1141 | 90 | public function free() |
|
| 1155 | |||
| 1156 | /** |
||
| 1157 | * alias for "Result->fetch()" |
||
| 1158 | * |
||
| 1159 | * @see Result::fetch() |
||
| 1160 | * |
||
| 1161 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 1162 | */ |
||
| 1163 | 2 | public function get() |
|
| 1167 | |||
| 1168 | /** |
||
| 1169 | * alias for "Result->fetchAll()" |
||
| 1170 | * |
||
| 1171 | * @see Result::fetchAll() |
||
| 1172 | * |
||
| 1173 | * @return array |
||
| 1174 | */ |
||
| 1175 | 2 | public function getAll(): array |
|
| 1179 | |||
| 1180 | /** |
||
| 1181 | * alias for "Result->fetchAllColumn()" |
||
| 1182 | * |
||
| 1183 | * @see Result::fetchAllColumn() |
||
| 1184 | * |
||
| 1185 | * @param string $column |
||
| 1186 | * @param bool $skipNullValues |
||
| 1187 | * |
||
| 1188 | * @return array |
||
| 1189 | */ |
||
| 1190 | public function getAllColumn(string $column, bool $skipNullValues = false): array |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * alias for "Result->fetchAllArray()" |
||
| 1197 | * |
||
| 1198 | * @see Result::fetchAllArray() |
||
| 1199 | * |
||
| 1200 | * @return array |
||
| 1201 | */ |
||
| 1202 | 2 | public function getArray(): array |
|
| 1206 | |||
| 1207 | /** |
||
| 1208 | * alias for "Result->fetchAllArrayy()" |
||
| 1209 | * |
||
| 1210 | * @see Result::fetchAllArrayy() |
||
| 1211 | * |
||
| 1212 | * @return Arrayy |
||
| 1213 | */ |
||
| 1214 | public function getArrayy(): Arrayy |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * alias for "Result->fetchColumn()" |
||
| 1221 | * |
||
| 1222 | * @see Result::fetchColumn() |
||
| 1223 | * |
||
| 1224 | * @param string $column |
||
| 1225 | * @param bool $asArray |
||
| 1226 | * @param bool $skipNullValues |
||
| 1227 | * |
||
| 1228 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 1229 | * "$asArray"</p> |
||
| 1230 | */ |
||
| 1231 | 2 | public function getColumn(string $column, bool $skipNullValues = true, bool $asArray = false) |
|
| 1235 | |||
| 1236 | /** |
||
| 1237 | * @return string |
||
| 1238 | */ |
||
| 1239 | 2 | public function getDefaultResultType(): string |
|
| 1243 | |||
| 1244 | /** |
||
| 1245 | * alias for "Result->fetchAllObject()" |
||
| 1246 | * |
||
| 1247 | * @see Result::fetchAllObject() |
||
| 1248 | * |
||
| 1249 | * @return array of mysql-objects |
||
| 1250 | */ |
||
| 1251 | 2 | public function getObject(): array |
|
| 1255 | |||
| 1256 | /** |
||
| 1257 | * alias for "Result->fetchAllYield()" |
||
| 1258 | * |
||
| 1259 | * @see Result::fetchAllYield() |
||
| 1260 | * |
||
| 1261 | * @param bool $asArray |
||
| 1262 | * |
||
| 1263 | * @return \Generator |
||
| 1264 | */ |
||
| 1265 | public function getYield($asArray = false): \Generator |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Check if the result is empty. |
||
| 1272 | * |
||
| 1273 | * @return bool |
||
| 1274 | */ |
||
| 1275 | 46 | public function is_empty(): bool |
|
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Fetch all results as "json"-string. |
||
| 1282 | * |
||
| 1283 | * @return string |
||
| 1284 | */ |
||
| 1285 | 2 | public function json(): string |
|
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Returns the last row element from the result. |
||
| 1294 | * |
||
| 1295 | * @param string $column The column name to use as value (optional) |
||
| 1296 | * |
||
| 1297 | * @return mixed A row array or a single scalar value |
||
| 1298 | */ |
||
| 1299 | 3 | public function last(string $column = null) |
|
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Set the mapper... |
||
| 1310 | * |
||
| 1311 | * @param \Closure $callable |
||
| 1312 | * |
||
| 1313 | * @return $this |
||
| 1314 | */ |
||
| 1315 | 1 | public function map(\Closure $callable) |
|
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Alias of count(). Deprecated. |
||
| 1324 | * |
||
| 1325 | * @return int The number of rows in the result |
||
| 1326 | */ |
||
| 1327 | 1 | public function num_rows(): int |
|
| 1331 | |||
| 1332 | /** |
||
| 1333 | * ArrayAccess interface implementation. |
||
| 1334 | * |
||
| 1335 | * @param int $offset <p>Offset number</p> |
||
| 1336 | * |
||
| 1337 | * @return bool <p>true if offset exists, false otherwise</p> |
||
| 1338 | */ |
||
| 1339 | 1 | public function offsetExists($offset): bool |
|
| 1343 | |||
| 1344 | /** |
||
| 1345 | * ArrayAccess interface implementation. |
||
| 1346 | * |
||
| 1347 | * @param int $offset Offset number |
||
| 1348 | * |
||
| 1349 | * @return mixed |
||
| 1350 | */ |
||
| 1351 | 1 | public function offsetGet($offset) |
|
| 1359 | |||
| 1360 | /** |
||
| 1361 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1362 | * |
||
| 1363 | * @param mixed $offset |
||
| 1364 | * @param mixed $value |
||
| 1365 | */ |
||
| 1366 | public function offsetSet($offset, $value) |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1374 | * |
||
| 1375 | * @param mixed $offset |
||
| 1376 | */ |
||
| 1377 | public function offsetUnset($offset) |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Reset the offset (data_seek) for the results. |
||
| 1385 | * |
||
| 1386 | * @return Result |
||
| 1387 | */ |
||
| 1388 | 43 | public function reset(): self |
|
| 1403 | |||
| 1404 | /** |
||
| 1405 | * You can set the default result-type to Result::RESULT_TYPE_*. |
||
| 1406 | * |
||
| 1407 | * INFO: used for "fetch()" and "fetchAll()" |
||
| 1408 | * |
||
| 1409 | * @param string $default_result_type |
||
| 1410 | */ |
||
| 1411 | 4 | public function setDefaultResultType(string $default_result_type = self::RESULT_TYPE_OBJECT) |
|
| 1425 | |||
| 1426 | /** |
||
| 1427 | * @param int $offset |
||
| 1428 | * @param null|int $length |
||
| 1429 | * @param bool $preserve_keys |
||
| 1430 | * |
||
| 1431 | * @return array |
||
| 1432 | */ |
||
| 1433 | 1 | public function slice(int $offset = 0, int $length = null, bool $preserve_keys = false): array |
|
| 1459 | } |
||
| 1460 |
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: