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 | * Result constructor. |
||
| 95 | * |
||
| 96 | * @param string $sql |
||
| 97 | * @param \mysqli_result $result |
||
| 98 | * @param \Closure $mapper Optional callback mapper for the "fetchCallable()" method |
||
| 99 | */ |
||
| 100 | 91 | public function __construct(string $sql, $result, \Closure $mapper = null) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * __destruct |
||
| 141 | */ |
||
| 142 | 90 | public function __destruct() |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Runs a user-provided callback with the MySQLi_Result object given as |
||
| 149 | * argument and returns the result, or returns the MySQLi_Result object if |
||
| 150 | * called without an argument. |
||
| 151 | * |
||
| 152 | * @param callable $callback User-provided callback (optional) |
||
| 153 | * |
||
| 154 | * @return mixed|\Doctrine\DBAL\Statement|\mysqli_result |
||
| 155 | */ |
||
| 156 | 2 | public function __invoke(callable $callback = null) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Get the current "num_rows" as string. |
||
| 167 | * |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function __toString() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Cast data into int, float or string. |
||
| 177 | * |
||
| 178 | * <p> |
||
| 179 | * <br /> |
||
| 180 | * INFO: install / use "mysqlnd"-driver for better performance |
||
| 181 | * </p> |
||
| 182 | * |
||
| 183 | * @param array|object $data |
||
| 184 | * |
||
| 185 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 186 | */ |
||
| 187 | 64 | private function cast(&$data) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * Countable interface implementation. |
||
| 260 | * |
||
| 261 | * @return int The number of rows in the result |
||
| 262 | */ |
||
| 263 | 2 | public function count(): int |
|
| 267 | |||
| 268 | /** |
||
| 269 | * Iterator interface implementation. |
||
| 270 | * |
||
| 271 | * @return mixed The current element |
||
| 272 | */ |
||
| 273 | 7 | public function current() |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Iterator interface implementation. |
||
| 280 | * |
||
| 281 | * @return int The current element key (row index; zero-based) |
||
| 282 | */ |
||
| 283 | 1 | public function key(): int |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Iterator interface implementation. |
||
| 290 | * |
||
| 291 | * @return void |
||
| 292 | */ |
||
| 293 | 7 | public function next() |
|
| 297 | |||
| 298 | /** |
||
| 299 | * Iterator interface implementation. |
||
| 300 | * |
||
| 301 | * @param int $row Row position to rewind to; defaults to 0 |
||
| 302 | * |
||
| 303 | * @return void |
||
| 304 | */ |
||
| 305 | 11 | public function rewind($row = 0) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * Moves the internal pointer to the specified row position. |
||
| 314 | * |
||
| 315 | * @param int $row <p>Row position; zero-based and set to 0 by default</p> |
||
| 316 | * |
||
| 317 | * @return bool <p>true on success, false otherwise</p> |
||
| 318 | */ |
||
| 319 | 19 | public function seek($row = 0): bool |
|
| 338 | |||
| 339 | /** |
||
| 340 | * Iterator interface implementation. |
||
| 341 | * |
||
| 342 | * @return bool <p>true if the current index is valid, false otherwise</p> |
||
| 343 | */ |
||
| 344 | 7 | public function valid(): bool |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Fetch. |
||
| 351 | * |
||
| 352 | * <p> |
||
| 353 | * <br /> |
||
| 354 | * INFO: this will return an object by default, not an array<br /> |
||
| 355 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 356 | * </p> |
||
| 357 | * |
||
| 358 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 359 | * |
||
| 360 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 361 | */ |
||
| 362 | 4 | public function fetch(bool $reset = false) |
|
| 378 | |||
| 379 | /** |
||
| 380 | * Fetch all results. |
||
| 381 | * |
||
| 382 | * <p> |
||
| 383 | * <br /> |
||
| 384 | * INFO: this will return an object by default, not an array<br /> |
||
| 385 | * and you can change the behaviour via "Result->setDefaultResultType()" |
||
| 386 | * </p> |
||
| 387 | * |
||
| 388 | * @return array |
||
| 389 | */ |
||
| 390 | 4 | public function fetchAll(): array |
|
| 406 | |||
| 407 | /** |
||
| 408 | * Fetch all results as array. |
||
| 409 | * |
||
| 410 | * @return array |
||
| 411 | */ |
||
| 412 | 20 | public function fetchAllArray(): array |
|
| 428 | |||
| 429 | /** |
||
| 430 | * Fetch all results as "Arrayy"-object. |
||
| 431 | * |
||
| 432 | * @return Arrayy |
||
| 433 | */ |
||
| 434 | 7 | public function fetchAllArrayy(): Arrayy |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Fetch a single column as an 1-dimension array. |
||
| 453 | * |
||
| 454 | * @param string $column |
||
| 455 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: false</p> |
||
| 456 | * |
||
| 457 | * @return array <p>Return an empty array if the "$column" wasn't found</p> |
||
| 458 | */ |
||
| 459 | 4 | public function fetchAllColumn(string $column, bool $skipNullValues = false): array |
|
| 463 | |||
| 464 | /** |
||
| 465 | * Fetch all results as array with objects. |
||
| 466 | * |
||
| 467 | * @param object|string $class <p> |
||
| 468 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 469 | * parameter)<br> |
||
| 470 | * <strong>object</strong>: use a object and fill the the data into |
||
| 471 | * </p> |
||
| 472 | * @param null|array $params optional |
||
| 473 | * <p> |
||
| 474 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 475 | * string. |
||
| 476 | * </p> |
||
| 477 | * |
||
| 478 | * @return array |
||
| 479 | */ |
||
| 480 | 14 | public function fetchAllObject($class = '', array $params = null): array |
|
| 528 | |||
| 529 | /** |
||
| 530 | * Fetch all results as "\Generator" via yield. |
||
| 531 | * |
||
| 532 | * @param object|string $class <p> |
||
| 533 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 534 | * parameter)<br> |
||
| 535 | * <strong>object</strong>: use a object and fill the the data into |
||
| 536 | * </p> |
||
| 537 | * @param null|array $params optional |
||
| 538 | * <p> |
||
| 539 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 540 | * string. |
||
| 541 | * </p> |
||
| 542 | * |
||
| 543 | * @return \Generator |
||
| 544 | */ |
||
| 545 | 6 | public function fetchAllYield($class = '', array $params = null): \Generator |
|
| 590 | |||
| 591 | /** |
||
| 592 | * Fetch as array. |
||
| 593 | * |
||
| 594 | * @param bool $reset |
||
| 595 | * |
||
| 596 | * @return array|false <p><strong>false</strong> on error</p> |
||
| 597 | */ |
||
| 598 | 23 | View Code Duplication | public function fetchArray(bool $reset = false) |
| 615 | |||
| 616 | /** |
||
| 617 | * Fetch data as a key/value pair array. |
||
| 618 | * |
||
| 619 | * <p> |
||
| 620 | * <br /> |
||
| 621 | * INFO: both "key" and "value" must exists in the fetched data |
||
| 622 | * the key will be the new key of the result-array |
||
| 623 | * <br /><br /> |
||
| 624 | * </p> |
||
| 625 | * |
||
| 626 | * e.g.: |
||
| 627 | * <code> |
||
| 628 | * fetchArrayPair('some_id', 'some_value'); |
||
| 629 | * // array(127 => 'some value', 128 => 'some other value') |
||
| 630 | * </code> |
||
| 631 | * |
||
| 632 | * @param string $key |
||
| 633 | * @param string $value |
||
| 634 | * |
||
| 635 | * @return array |
||
| 636 | */ |
||
| 637 | 2 | public function fetchArrayPair(string $key, string $value): array |
|
| 656 | |||
| 657 | /** |
||
| 658 | * Fetch as "Arrayy"-object. |
||
| 659 | * |
||
| 660 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 661 | * |
||
| 662 | * @return Arrayy|false <p><strong>false</strong> on error</p> |
||
| 663 | */ |
||
| 664 | 4 | View Code Duplication | public function fetchArrayy(bool $reset = false) |
| 681 | |||
| 682 | /** |
||
| 683 | * Fetches a row or a single column within a row. Returns null if there are |
||
| 684 | * no more rows in the result. |
||
| 685 | * |
||
| 686 | * @param int $row The row number (optional) |
||
| 687 | * @param string $column The column name (optional) |
||
| 688 | * |
||
| 689 | * @return mixed An associative array or a scalar value |
||
| 690 | */ |
||
| 691 | 16 | public function fetchCallable(int $row = null, string $column = null) |
|
| 709 | |||
| 710 | /** |
||
| 711 | * Fetch a single column as string (or as 1-dimension array). |
||
| 712 | * |
||
| 713 | * @param string $column |
||
| 714 | * @param bool $skipNullValues <p>Skip "NULL"-values. | default: true</p> |
||
| 715 | * @param bool $asArray <p>Get all values and not only the last one. | default: false</p> |
||
| 716 | * |
||
| 717 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 718 | * "$asArray"</p> |
||
| 719 | */ |
||
| 720 | 7 | public function fetchColumn(string $column = '', bool $skipNullValues = true, bool $asArray = false) |
|
| 762 | |||
| 763 | /** |
||
| 764 | * Return rows of field information in a result set. |
||
| 765 | * |
||
| 766 | * @param bool $as_array Return each field info as array; defaults to false |
||
| 767 | * |
||
| 768 | * @return array Array of field information each as an associative array |
||
| 769 | */ |
||
| 770 | 1 | public function fetchFields(bool $as_array = false): array |
|
| 783 | |||
| 784 | /** |
||
| 785 | * Returns all rows at once as a grouped array of scalar values or arrays. |
||
| 786 | * |
||
| 787 | * @param string $group The column name to use for grouping |
||
| 788 | * @param string $column The column name to use as values (optional) |
||
| 789 | * |
||
| 790 | * @return array A grouped array of scalar values or arrays |
||
| 791 | */ |
||
| 792 | 1 | View Code Duplication | public function fetchGroups(string $group, string $column = null): array |
| 820 | |||
| 821 | /** |
||
| 822 | * Fetch as object. |
||
| 823 | * |
||
| 824 | * @param object|string $class <p> |
||
| 825 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 826 | * parameter)<br> |
||
| 827 | * <strong>object</strong>: use a object and fill the the data into |
||
| 828 | * </p> |
||
| 829 | * @param null|array $params optional |
||
| 830 | * <p> |
||
| 831 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 832 | * string. |
||
| 833 | * </p> |
||
| 834 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 835 | * |
||
| 836 | * @return object|false <p><strong>false</strong> on error</p> |
||
| 837 | */ |
||
| 838 | 25 | View Code Duplication | public function fetchObject($class = '', array $params = null, bool $reset = false) |
| 883 | |||
| 884 | /** |
||
| 885 | * Returns all rows at once as key-value pairs. |
||
| 886 | * |
||
| 887 | * @param string $key The column name to use as keys |
||
| 888 | * @param string $column The column name to use as values (optional) |
||
| 889 | * |
||
| 890 | * @return array An array of key-value pairs |
||
| 891 | */ |
||
| 892 | 1 | View Code Duplication | public function fetchPairs(string $key, string $column = null): array |
| 920 | |||
| 921 | /** |
||
| 922 | * Returns all rows at once, transposed as an array of arrays. Instead of |
||
| 923 | * returning rows of columns, this method returns columns of rows. |
||
| 924 | * |
||
| 925 | * @param string $column The column name to use as keys (optional) |
||
| 926 | * |
||
| 927 | * @return mixed A transposed array of arrays |
||
| 928 | */ |
||
| 929 | 1 | public function fetchTranspose(string $column = null) |
|
| 954 | |||
| 955 | /** |
||
| 956 | * Fetch as "\Generator" via yield. |
||
| 957 | * |
||
| 958 | * @param object|string $class <p> |
||
| 959 | * <strong>string</strong>: create a new object (with optional constructor |
||
| 960 | * parameter)<br> |
||
| 961 | * <strong>object</strong>: use a object and fill the the data into |
||
| 962 | * </p> |
||
| 963 | * @param null|array $params optional |
||
| 964 | * <p> |
||
| 965 | * An array of parameters to pass to the constructor, used if $class is a |
||
| 966 | * string. |
||
| 967 | * </p> |
||
| 968 | * @param bool $reset optional <p>Reset the \mysqli_result counter.</p> |
||
| 969 | * |
||
| 970 | * @return \Generator |
||
| 971 | */ |
||
| 972 | 2 | View Code Duplication | public function fetchYield($class = '', array $params = null, bool $reset = false): \Generator |
| 1017 | |||
| 1018 | /** |
||
| 1019 | * @return mixed |
||
| 1020 | */ |
||
| 1021 | 76 | private function fetch_assoc() |
|
| 1032 | |||
| 1033 | /** |
||
| 1034 | * @return array|bool |
||
| 1035 | */ |
||
| 1036 | 1 | private function fetch_fields() |
|
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Returns the first row element from the result. |
||
| 1083 | * |
||
| 1084 | * @param string $column The column name to use as value (optional) |
||
| 1085 | * |
||
| 1086 | * @return mixed A row array or a single scalar value |
||
| 1087 | */ |
||
| 1088 | 3 | public function first(string $column = null) |
|
| 1096 | |||
| 1097 | /** |
||
| 1098 | * free the memory |
||
| 1099 | */ |
||
| 1100 | 90 | public function free() |
|
| 1114 | |||
| 1115 | /** |
||
| 1116 | * alias for "Result->fetch()" |
||
| 1117 | * |
||
| 1118 | * @see Result::fetch() |
||
| 1119 | * |
||
| 1120 | * @return array|object|false <p><strong>false</strong> on error</p> |
||
| 1121 | */ |
||
| 1122 | 2 | public function get() |
|
| 1126 | |||
| 1127 | /** |
||
| 1128 | * alias for "Result->fetchAll()" |
||
| 1129 | * |
||
| 1130 | * @see Result::fetchAll() |
||
| 1131 | * |
||
| 1132 | * @return array |
||
| 1133 | */ |
||
| 1134 | 2 | public function getAll(): array |
|
| 1138 | |||
| 1139 | /** |
||
| 1140 | * alias for "Result->fetchAllColumn()" |
||
| 1141 | * |
||
| 1142 | * @see Result::fetchAllColumn() |
||
| 1143 | * |
||
| 1144 | * @param string $column |
||
| 1145 | * @param bool $skipNullValues |
||
| 1146 | * |
||
| 1147 | * @return array |
||
| 1148 | */ |
||
| 1149 | public function getAllColumn(string $column, bool $skipNullValues = false): array |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * alias for "Result->fetchAllArray()" |
||
| 1156 | * |
||
| 1157 | * @see Result::fetchAllArray() |
||
| 1158 | * |
||
| 1159 | * @return array |
||
| 1160 | */ |
||
| 1161 | 2 | public function getArray(): array |
|
| 1165 | |||
| 1166 | /** |
||
| 1167 | * alias for "Result->fetchAllArrayy()" |
||
| 1168 | * |
||
| 1169 | * @see Result::fetchAllArrayy() |
||
| 1170 | * |
||
| 1171 | * @return Arrayy |
||
| 1172 | */ |
||
| 1173 | public function getArrayy(): Arrayy |
||
| 1177 | |||
| 1178 | /** |
||
| 1179 | * alias for "Result->fetchColumn()" |
||
| 1180 | * |
||
| 1181 | * @see Result::fetchColumn() |
||
| 1182 | * |
||
| 1183 | * @param string $column |
||
| 1184 | * @param bool $asArray |
||
| 1185 | * @param bool $skipNullValues |
||
| 1186 | * |
||
| 1187 | * @return string|array <p>Return a empty string or an empty array if the "$column" wasn't found, depend on |
||
| 1188 | * "$asArray"</p> |
||
| 1189 | */ |
||
| 1190 | 2 | public function getColumn(string $column, bool $skipNullValues = true, bool $asArray = false) |
|
| 1194 | |||
| 1195 | /** |
||
| 1196 | * @return string |
||
| 1197 | */ |
||
| 1198 | 2 | public function getDefaultResultType(): string |
|
| 1202 | |||
| 1203 | /** |
||
| 1204 | * alias for "Result->fetchAllObject()" |
||
| 1205 | * |
||
| 1206 | * @see Result::fetchAllObject() |
||
| 1207 | * |
||
| 1208 | * @return array of mysql-objects |
||
| 1209 | */ |
||
| 1210 | 2 | public function getObject(): array |
|
| 1214 | |||
| 1215 | /** |
||
| 1216 | * alias for "Result->fetchAllYield()" |
||
| 1217 | * |
||
| 1218 | * @see Result::fetchAllYield() |
||
| 1219 | * |
||
| 1220 | * @param bool $asArray |
||
| 1221 | * |
||
| 1222 | * @return \Generator |
||
| 1223 | */ |
||
| 1224 | public function getYield($asArray = false): \Generator |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Check if the result is empty. |
||
| 1231 | * |
||
| 1232 | * @return bool |
||
| 1233 | */ |
||
| 1234 | 46 | public function is_empty(): bool |
|
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Fetch all results as "json"-string. |
||
| 1241 | * |
||
| 1242 | * @return string |
||
| 1243 | */ |
||
| 1244 | 2 | public function json(): string |
|
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Returns the last row element from the result. |
||
| 1253 | * |
||
| 1254 | * @param string $column The column name to use as value (optional) |
||
| 1255 | * |
||
| 1256 | * @return mixed A row array or a single scalar value |
||
| 1257 | */ |
||
| 1258 | 3 | public function last(string $column = null) |
|
| 1266 | |||
| 1267 | /** |
||
| 1268 | * Set the mapper... |
||
| 1269 | * |
||
| 1270 | * @param \Closure $callable |
||
| 1271 | * |
||
| 1272 | * @return $this |
||
| 1273 | */ |
||
| 1274 | 1 | public function map(\Closure $callable): self |
|
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Alias of count(). Deprecated. |
||
| 1283 | * |
||
| 1284 | * @return int The number of rows in the result |
||
| 1285 | */ |
||
| 1286 | 1 | public function num_rows(): int |
|
| 1290 | |||
| 1291 | /** |
||
| 1292 | * ArrayAccess interface implementation. |
||
| 1293 | * |
||
| 1294 | * @param int $offset <p>Offset number</p> |
||
| 1295 | * |
||
| 1296 | * @return bool <p>true if offset exists, false otherwise</p> |
||
| 1297 | */ |
||
| 1298 | 1 | public function offsetExists($offset): bool |
|
| 1302 | |||
| 1303 | /** |
||
| 1304 | * ArrayAccess interface implementation. |
||
| 1305 | * |
||
| 1306 | * @param int $offset Offset number |
||
| 1307 | * |
||
| 1308 | * @return mixed |
||
| 1309 | */ |
||
| 1310 | 1 | public function offsetGet($offset) |
|
| 1318 | |||
| 1319 | /** |
||
| 1320 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1321 | * |
||
| 1322 | * @param mixed $offset |
||
| 1323 | * @param mixed $value |
||
| 1324 | */ |
||
| 1325 | public function offsetSet($offset, $value) |
||
| 1330 | |||
| 1331 | /** |
||
| 1332 | * ArrayAccess interface implementation. Not implemented by design. |
||
| 1333 | * |
||
| 1334 | * @param mixed $offset |
||
| 1335 | */ |
||
| 1336 | public function offsetUnset($offset) |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Reset the offset (data_seek) for the results. |
||
| 1344 | * |
||
| 1345 | * @return Result |
||
| 1346 | */ |
||
| 1347 | 43 | public function reset(): self |
|
| 1362 | |||
| 1363 | /** |
||
| 1364 | * You can set the default result-type to Result::RESULT_TYPE_*. |
||
| 1365 | * |
||
| 1366 | * INFO: used for "fetch()" and "fetchAll()" |
||
| 1367 | * |
||
| 1368 | * @param string $default_result_type |
||
| 1369 | */ |
||
| 1370 | 4 | public function setDefaultResultType(string $default_result_type = self::RESULT_TYPE_OBJECT) |
|
| 1384 | |||
| 1385 | /** |
||
| 1386 | * @param int $offset |
||
| 1387 | * @param null|int $length |
||
| 1388 | * @param bool $preserve_keys |
||
| 1389 | * |
||
| 1390 | * @return array |
||
| 1391 | */ |
||
| 1392 | 1 | public function slice(int $offset = 0, int $length = null, bool $preserve_keys = false): array |
|
| 1418 | } |
||
| 1419 |
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: