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 Arrayy 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 Arrayy, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Arrayy extends \ArrayObject implements \ArrayAccess, \Serializable, \Countable |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $array = array(); |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $pathSeparator = '.'; |
||
26 | |||
27 | /** @noinspection MagicMethodsValidityInspection */ |
||
28 | /** |
||
29 | * Initializes |
||
30 | * |
||
31 | * @param array $array |
||
32 | */ |
||
33 | 748 | public function __construct($array = array()) |
|
39 | |||
40 | /** |
||
41 | * Get a value by key. |
||
42 | * |
||
43 | * @param $key |
||
44 | * |
||
45 | * @return mixed Get a Value from the current array. |
||
46 | */ |
||
47 | 1 | public function __get($key) |
|
57 | |||
58 | /** |
||
59 | * Call object as function. |
||
60 | * |
||
61 | * @param mixed $key |
||
62 | * |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function __invoke($key = null) |
||
66 | { |
||
67 | if ($key !== null) { |
||
68 | if (isset($this->array[$key])) { |
||
69 | return $this->array[$key]; |
||
70 | } |
||
71 | |||
72 | return false; |
||
73 | } |
||
74 | |||
75 | return (array)$this->array; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Whether or not an element exists by key. |
||
80 | * |
||
81 | * @param mixed $key |
||
82 | * |
||
83 | * @return bool True is the key/index exists, otherwise false. |
||
84 | */ |
||
85 | public function __isset($key) |
||
89 | |||
90 | /** |
||
91 | * Assigns a value to the specified element. |
||
92 | * |
||
93 | * @param mixed $key |
||
94 | * @param mixed $value |
||
95 | */ |
||
96 | 2 | public function __set($key, $value) |
|
100 | |||
101 | /** |
||
102 | * magic to string |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 16 | public function __toString() |
|
110 | |||
111 | /** |
||
112 | * Unset element by key. |
||
113 | * |
||
114 | * @param mixed $key |
||
115 | */ |
||
116 | public function __unset($key) |
||
120 | |||
121 | /** |
||
122 | * alias: for "Arrayy->append()" |
||
123 | * |
||
124 | * @see Arrayy::append() |
||
125 | * |
||
126 | * @param mixed $value |
||
127 | * |
||
128 | * @return static (Mutable) Return this Arrayy object, with the appended values. |
||
129 | */ |
||
130 | 1 | public function add($value) |
|
134 | |||
135 | /** |
||
136 | * Append a value to the current array. |
||
137 | * |
||
138 | * @param mixed $value |
||
139 | * |
||
140 | * @return static (Mutable) Return this Arrayy object, with the appended values. |
||
141 | */ |
||
142 | 9 | public function append($value) |
|
148 | |||
149 | /** |
||
150 | * Count the values from the current array. |
||
151 | * |
||
152 | * alias: for "Arrayy->size()" |
||
153 | * |
||
154 | * @see Arrayy::size() |
||
155 | * |
||
156 | * @return int |
||
157 | */ |
||
158 | 93 | public function count() |
|
162 | |||
163 | /** |
||
164 | * Returns a new ArrayyIterator, thus implementing the IteratorAggregate interface. |
||
165 | * |
||
166 | * @return ArrayyIterator An iterator for the values in the array. |
||
167 | */ |
||
168 | 19 | public function getIterator() |
|
172 | |||
173 | /** |
||
174 | * Whether or not an offset exists. |
||
175 | * |
||
176 | * @param int|float|string $offset |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | 38 | public function offsetExists($offset) |
|
224 | |||
225 | /** |
||
226 | * Returns the value at specified offset. |
||
227 | * |
||
228 | * @param mixed $offset |
||
229 | * |
||
230 | * @return mixed return null if the offset did not exists |
||
231 | */ |
||
232 | 24 | public function offsetGet($offset) |
|
236 | |||
237 | /** |
||
238 | * Assigns a value to the specified offset. |
||
239 | * |
||
240 | * @param mixed $offset |
||
241 | * @param mixed $value |
||
242 | */ |
||
243 | 15 | public function offsetSet($offset, $value) |
|
251 | |||
252 | /** |
||
253 | * Unset an offset. |
||
254 | * |
||
255 | * @param mixed $offset |
||
256 | */ |
||
257 | 6 | public function offsetUnset($offset) |
|
283 | |||
284 | /** |
||
285 | * Serialize the current array. |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | 2 | public function serialize() |
|
293 | |||
294 | /** |
||
295 | * Unserialize an string and return this object. |
||
296 | * |
||
297 | * @param string $string |
||
298 | * |
||
299 | * @return static (Mutable) |
||
300 | */ |
||
301 | 2 | public function unserialize($string) |
|
307 | |||
308 | /** |
||
309 | * Iterate over the current array and execute a callback for each loop. |
||
310 | * |
||
311 | * @param \Closure $closure |
||
312 | * |
||
313 | * @return static (Immutable) |
||
314 | */ |
||
315 | 2 | View Code Duplication | public function at(\Closure $closure) |
325 | |||
326 | /** |
||
327 | * Returns the average value of the current array. |
||
328 | * |
||
329 | * @param int $decimals The number of decimals to return |
||
330 | * |
||
331 | * @return int|double The average value |
||
332 | */ |
||
333 | 10 | public function average($decimals = 0) |
|
347 | |||
348 | /** |
||
349 | * @param mixed $path |
||
350 | * @param callable $callable |
||
351 | * @param null|array $currentOffset |
||
352 | */ |
||
353 | 2 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
376 | |||
377 | /** |
||
378 | * Change the path separator of the array wrapper. |
||
379 | * |
||
380 | * By default, the separator is: . |
||
381 | * |
||
382 | * @param string $separator Separator to set. |
||
383 | * |
||
384 | * @return static Current instance. |
||
385 | */ |
||
386 | public function changeSeparator($separator) |
||
392 | |||
393 | /** |
||
394 | * Create a chunked version of the current array. |
||
395 | * |
||
396 | * @param int $size Size of each chunk |
||
397 | * @param bool $preserveKeys Whether array keys are preserved or no |
||
398 | * |
||
399 | * @return static (Immutable) A new array of chunks from the original array. |
||
400 | */ |
||
401 | 4 | public function chunk($size, $preserveKeys = false) |
|
407 | |||
408 | /** |
||
409 | * Clean all falsy values from the current array. |
||
410 | * |
||
411 | * @return static (Immutable) |
||
412 | */ |
||
413 | 8 | public function clean() |
|
421 | |||
422 | /** |
||
423 | * WARNING!!! -> Clear the current array. |
||
424 | * |
||
425 | * @return static (Mutable) Return this Arrayy object, with an empty array. |
||
426 | */ |
||
427 | 4 | public function clear() |
|
433 | |||
434 | /** |
||
435 | * Check if an item is in the current array. |
||
436 | * |
||
437 | * @param string|int|float $value |
||
438 | * |
||
439 | * @return bool |
||
440 | */ |
||
441 | 13 | public function contains($value) |
|
445 | |||
446 | /** |
||
447 | * Check if an (case-insensitive) string is in the current array. |
||
448 | * |
||
449 | * @param string $value |
||
450 | * |
||
451 | * @return bool |
||
452 | */ |
||
453 | 13 | public function containsCaseInsensitive($value) |
|
467 | |||
468 | /** |
||
469 | * Check if the given key/index exists in the array. |
||
470 | * |
||
471 | * @param string|int|float $key key/index to search for |
||
472 | * |
||
473 | * @return bool Returns true if the given key/index exists in the array, false otherwise |
||
474 | */ |
||
475 | 4 | public function containsKey($key) |
|
479 | |||
480 | /** |
||
481 | * Check if all given needles are present in the array as key/index. |
||
482 | * |
||
483 | * @param array $needles |
||
484 | * |
||
485 | * @return bool Returns true if the given keys/indexes exists in the array, false otherwise |
||
486 | */ |
||
487 | 1 | public function containsKeys(array $needles) |
|
491 | |||
492 | /** |
||
493 | * alias: for "Arrayy->contains()" |
||
494 | * |
||
495 | * @see Arrayy::contains() |
||
496 | * |
||
497 | * @param string|int|float $value |
||
498 | * |
||
499 | * @return bool |
||
500 | */ |
||
501 | public function containsValue($value) |
||
505 | |||
506 | /** |
||
507 | * Check if all given needles are present in the array. |
||
508 | * |
||
509 | * @param array $needles |
||
510 | * |
||
511 | * @return bool Returns true if the given values exists in the array, false otherwise |
||
512 | */ |
||
513 | 1 | public function containsValues(array $needles) |
|
517 | |||
518 | /** |
||
519 | * Creates an Arrayy object. |
||
520 | * |
||
521 | * @param array $array |
||
522 | * |
||
523 | * @return static (Immutable) Returns an new instance of the Arrayy object. |
||
524 | */ |
||
525 | 468 | public static function create($array = array()) |
|
529 | |||
530 | /** |
||
531 | * WARNING: Creates an Arrayy object by reference. |
||
532 | * |
||
533 | * @param array $array |
||
534 | * |
||
535 | * @return static (Mutable) Return this Arrayy object. |
||
536 | */ |
||
537 | public function createByReference(&$array = array()) |
||
545 | |||
546 | /** |
||
547 | * Create an new Arrayy object via JSON. |
||
548 | * |
||
549 | * @param string $json |
||
550 | * |
||
551 | * @return static (Immutable) Returns an new instance of the Arrayy object. |
||
552 | */ |
||
553 | 5 | public static function createFromJson($json) |
|
559 | |||
560 | /** |
||
561 | * Create an new instance filled with values from an object that have implemented ArrayAccess. |
||
562 | * |
||
563 | * @param \ArrayAccess $object Object that implements ArrayAccess |
||
564 | * |
||
565 | * @return static (Immutable) Returns an new instance of the Arrayy object. |
||
566 | */ |
||
567 | 4 | public static function createFromObject(\ArrayAccess $object) |
|
577 | |||
578 | /** |
||
579 | * Create an new Arrayy object via string. |
||
580 | * |
||
581 | * @param string $str The input string. |
||
582 | * @param string|null $delimiter The boundary string. |
||
583 | * @param string|null $regEx Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be used. |
||
584 | * |
||
585 | * @return static (Immutable) Returns an new instance of the Arrayy object. |
||
586 | */ |
||
587 | 8 | public static function createFromString($str, $delimiter, $regEx = null) |
|
613 | |||
614 | /** |
||
615 | * Create an new instance containing a range of elements. |
||
616 | * |
||
617 | * @param mixed $low First value of the sequence |
||
618 | * @param mixed $high The sequence is ended upon reaching the end value |
||
619 | * @param int $step Used as the increment between elements in the sequence |
||
620 | * |
||
621 | * @return static (Immutable) Returns an new instance of the Arrayy object. |
||
622 | */ |
||
623 | 1 | public static function createWithRange($low, $high, $step = 1) |
|
627 | |||
628 | /** |
||
629 | * Custom sort by index via "uksort". |
||
630 | * |
||
631 | * @link http://php.net/manual/en/function.uksort.php |
||
632 | * |
||
633 | * @param callable $function |
||
634 | * |
||
635 | * @return static (Mutable) Return this Arrayy object. |
||
636 | */ |
||
637 | 5 | public function customSortKeys($function) |
|
643 | |||
644 | /** |
||
645 | * Custom sort by value via "usort". |
||
646 | * |
||
647 | * @link http://php.net/manual/en/function.usort.php |
||
648 | * |
||
649 | * @param callable $function |
||
650 | * |
||
651 | * @return static (Mutable) Return this Arrayy object. |
||
652 | */ |
||
653 | 4 | public function customSortValues($function) |
|
659 | |||
660 | /** |
||
661 | * Return values that are only in the current array. |
||
662 | * |
||
663 | * @param array $array |
||
664 | * |
||
665 | * @return static (Immutable) |
||
666 | */ |
||
667 | 12 | public function diff(array $array = array()) |
|
673 | |||
674 | /** |
||
675 | * Return values that are only in the current multi-dimensional array. |
||
676 | * |
||
677 | * @param array $array |
||
678 | * @param null|array $helperVariableForRecursion (only for internal usage) |
||
679 | * |
||
680 | * @return static (Immutable) |
||
681 | */ |
||
682 | 1 | public function diffRecursive(array $array = array(), $helperVariableForRecursion = null) |
|
715 | |||
716 | /** |
||
717 | * Return values that are only in the new $array. |
||
718 | * |
||
719 | * @param array $array |
||
720 | * |
||
721 | * @return static (Immutable) |
||
722 | */ |
||
723 | 8 | public function diffReverse(array $array = array()) |
|
729 | |||
730 | /** |
||
731 | * Divide an array into two arrays. One with keys and the other with values. |
||
732 | * |
||
733 | * @return static (Immutable) |
||
734 | */ |
||
735 | 1 | public function divide() |
|
744 | |||
745 | /** |
||
746 | * Iterate over the current array and modify the array's value. |
||
747 | * |
||
748 | * @param \Closure $closure |
||
749 | * |
||
750 | * @return static (Immutable) |
||
751 | */ |
||
752 | 4 | View Code Duplication | public function each(\Closure $closure) |
762 | |||
763 | /** |
||
764 | * Check if a value is in the current array using a closure. |
||
765 | * |
||
766 | * @param \Closure $closure |
||
767 | * |
||
768 | * @return bool Returns true if the given value is found, false otherwise |
||
769 | */ |
||
770 | 4 | public function exists(\Closure $closure) |
|
782 | |||
783 | /** |
||
784 | * create a fallback for array |
||
785 | * |
||
786 | * 1. use the current array, if it's a array |
||
787 | * 2. call "getArray()" on object, if there is a "Arrayy"-object |
||
788 | * 3. fallback to empty array, if there is nothing |
||
789 | * 4. call "createFromObject()" on object, if there is a "\ArrayAccess"-object |
||
790 | * 5. call "__toArray()" on object, if the method exists |
||
791 | * 6. cast a string or object with "__toString()" into an array |
||
792 | * 7. throw a "InvalidArgumentException"-Exception |
||
793 | * |
||
794 | * @param $array |
||
795 | * |
||
796 | * @return array |
||
797 | * |
||
798 | * @throws \InvalidArgumentException |
||
799 | */ |
||
800 | 748 | protected function fallbackForArray(&$array) |
|
836 | |||
837 | /** |
||
838 | * Find all items in an array that pass the truth test. |
||
839 | * |
||
840 | * @param \Closure|null $closure |
||
841 | * |
||
842 | * @return static (Immutable) |
||
843 | */ |
||
844 | 9 | public function filter($closure = null) |
|
854 | |||
855 | /** |
||
856 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property |
||
857 | * within that. |
||
858 | * |
||
859 | * @param $property |
||
860 | * @param $value |
||
861 | * @param string $comparisonOp |
||
862 | * 'eq' (equals),<br /> |
||
863 | * 'gt' (greater),<br /> |
||
864 | * 'gte' || 'ge' (greater or equals),<br /> |
||
865 | * 'lt' (less),<br /> |
||
866 | * 'lte' || 'le' (less or equals),<br /> |
||
867 | * 'ne' (not equals),<br /> |
||
868 | * 'contains',<br /> |
||
869 | * 'notContains',<br /> |
||
870 | * 'newer' (via strtotime),<br /> |
||
871 | * 'older' (via strtotime),<br /> |
||
872 | * |
||
873 | * @return static (Immutable) |
||
874 | */ |
||
875 | 1 | public function filterBy($property, $value, $comparisonOp = null) |
|
940 | |||
941 | /** |
||
942 | * Find the first item in an array that passes the truth test, |
||
943 | * otherwise return false |
||
944 | * |
||
945 | * @param \Closure $closure |
||
946 | * |
||
947 | * @return mixed|false false if we did not find the value |
||
948 | */ |
||
949 | 8 | public function find(\Closure $closure) |
|
959 | |||
960 | /** |
||
961 | * find by ... |
||
962 | * |
||
963 | * @param $property |
||
964 | * @param $value |
||
965 | * @param string $comparisonOp |
||
966 | * |
||
967 | * @return static (Immutable) |
||
968 | */ |
||
969 | public function findBy($property, $value, $comparisonOp = 'eq') |
||
973 | |||
974 | /** |
||
975 | * Get the first value from the current array. |
||
976 | * |
||
977 | * @return mixed Return null if there wasn't a element. |
||
978 | */ |
||
979 | 13 | public function first() |
|
990 | |||
991 | /** |
||
992 | * Get the first value(s) from the current array. |
||
993 | * |
||
994 | * @param int|null $number how many values you will take? |
||
995 | * |
||
996 | * @return static (Immutable) |
||
997 | */ |
||
998 | 28 | public function firstsImmutable($number = null) |
|
1011 | |||
1012 | /** |
||
1013 | * Get the first value(s) from the current array. |
||
1014 | * |
||
1015 | * @param int|null $number how many values you will take? |
||
1016 | * |
||
1017 | * @return static (Mutable) |
||
1018 | */ |
||
1019 | 26 | public function firstsMutable($number = null) |
|
1030 | |||
1031 | /** |
||
1032 | * Exchanges all keys with their associated values in an array. |
||
1033 | * |
||
1034 | * @return static (Immutable) |
||
1035 | */ |
||
1036 | 1 | public function flip() |
|
1042 | |||
1043 | /** |
||
1044 | * Get a value from an array (optional using dot-notation). |
||
1045 | * |
||
1046 | * @param string $key The key to look for. |
||
1047 | * @param mixed $fallback Value to fallback to. |
||
1048 | * @param array $array The array to get from, if it's set to "null" we use the current array from the class. |
||
1049 | * |
||
1050 | * @return mixed |
||
1051 | */ |
||
1052 | 58 | public function get($key, $fallback = null, $array = null) |
|
1096 | |||
1097 | /** |
||
1098 | * Get the current array from the "Arrayy"-object. |
||
1099 | * |
||
1100 | * @return array |
||
1101 | */ |
||
1102 | 473 | public function getArray() |
|
1108 | |||
1109 | /** |
||
1110 | * @param mixed $value |
||
1111 | */ |
||
1112 | 389 | protected function internalGetArray(&$value) |
|
1118 | |||
1119 | /** |
||
1120 | * Returns the values from a single column of the input array, identified by |
||
1121 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
1122 | * |
||
1123 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
1124 | * array by the values from the $indexKey column in the input array. |
||
1125 | * |
||
1126 | * @param mixed $columnKey |
||
1127 | * @param mixed $indexKey |
||
1128 | * |
||
1129 | * @return static (Immutable) |
||
1130 | */ |
||
1131 | 1 | public function getColumn($columnKey = null, $indexKey = null) |
|
1137 | |||
1138 | /** |
||
1139 | * Get correct PHP constant for direction. |
||
1140 | * |
||
1141 | * @param int|string $direction |
||
1142 | * |
||
1143 | * @return int |
||
1144 | */ |
||
1145 | 38 | protected function getDirection($direction) |
|
1167 | |||
1168 | /** |
||
1169 | * alias: for "Arrayy->keys()" |
||
1170 | * |
||
1171 | * @see Arrayy::keys() |
||
1172 | * |
||
1173 | * @return static (Immutable) |
||
1174 | */ |
||
1175 | 1 | public function getKeys() |
|
1179 | |||
1180 | /** |
||
1181 | * alias: for "Arrayy->randomImmutable()" |
||
1182 | * |
||
1183 | * @see Arrayy::randomImmutable() |
||
1184 | * |
||
1185 | * @return static (Immutable) |
||
1186 | */ |
||
1187 | 3 | public function getRandom() |
|
1191 | |||
1192 | /** |
||
1193 | * alias: for "Arrayy->randomKey()" |
||
1194 | * |
||
1195 | * @see Arrayy::randomKey() |
||
1196 | * |
||
1197 | * @return mixed get a key/index or null if there wasn't a key/index |
||
1198 | */ |
||
1199 | 3 | public function getRandomKey() |
|
1203 | |||
1204 | /** |
||
1205 | * alias: for "Arrayy->randomKeys()" |
||
1206 | * |
||
1207 | * @see Arrayy::randomKeys() |
||
1208 | * |
||
1209 | * @param int $number |
||
1210 | * |
||
1211 | * @return static (Immutable) |
||
1212 | */ |
||
1213 | 9 | public function getRandomKeys($number) |
|
1217 | |||
1218 | /** |
||
1219 | * alias: for "Arrayy->randomValue()" |
||
1220 | * |
||
1221 | * @see Arrayy::randomValue() |
||
1222 | * |
||
1223 | * @return mixed get a random value or null if there wasn't a value |
||
1224 | */ |
||
1225 | 3 | public function getRandomValue() |
|
1229 | |||
1230 | /** |
||
1231 | * alias: for "Arrayy->randomValues()" |
||
1232 | * |
||
1233 | * @see Arrayy::randomValues() |
||
1234 | * |
||
1235 | * @param int $number |
||
1236 | * |
||
1237 | * @return static (Immutable) |
||
1238 | */ |
||
1239 | 6 | public function getRandomValues($number) |
|
1243 | |||
1244 | /** |
||
1245 | * Group values from a array according to the results of a closure. |
||
1246 | * |
||
1247 | * @param string $grouper a callable function name |
||
1248 | * @param bool $saveKeys |
||
1249 | * |
||
1250 | * @return static (Immutable) |
||
1251 | */ |
||
1252 | 3 | public function group($grouper, $saveKeys = false) |
|
1286 | |||
1287 | /** |
||
1288 | * Check if an array has a given key. |
||
1289 | * |
||
1290 | * @param mixed $key |
||
1291 | * |
||
1292 | * @return bool |
||
1293 | */ |
||
1294 | 22 | public function has($key) |
|
1301 | |||
1302 | /** |
||
1303 | * Implodes an array. |
||
1304 | * |
||
1305 | * @param string $with What to implode it with |
||
1306 | * |
||
1307 | * @return string |
||
1308 | */ |
||
1309 | 27 | public function implode($with = '') |
|
1313 | |||
1314 | /** |
||
1315 | * Given a list and an iterate-function that returns |
||
1316 | * a key for each element in the list (or a property name), |
||
1317 | * returns an object with an index of each item. |
||
1318 | * |
||
1319 | * Just like groupBy, but for when you know your keys are unique. |
||
1320 | * |
||
1321 | * @param mixed $key |
||
1322 | * |
||
1323 | * @return static (Immutable) |
||
1324 | */ |
||
1325 | 3 | public function indexBy($key) |
|
1337 | |||
1338 | /** |
||
1339 | * alias: for "Arrayy->searchIndex()" |
||
1340 | * |
||
1341 | * @see Arrayy::searchIndex() |
||
1342 | * |
||
1343 | * @param mixed $value Value to search for |
||
1344 | * |
||
1345 | * @return mixed |
||
1346 | */ |
||
1347 | 4 | public function indexOf($value) |
|
1351 | |||
1352 | /** |
||
1353 | * Get everything but the last..$to items. |
||
1354 | * |
||
1355 | * @param int $to |
||
1356 | * |
||
1357 | * @return static (Immutable) |
||
1358 | */ |
||
1359 | 12 | public function initial($to = 1) |
|
1365 | |||
1366 | /** |
||
1367 | * Internal mechanics of remove method. |
||
1368 | * |
||
1369 | * @param string $key |
||
1370 | * |
||
1371 | * @return boolean |
||
1372 | */ |
||
1373 | 18 | protected function internalRemove($key) |
|
1394 | |||
1395 | /** |
||
1396 | * Internal mechanic of set method. |
||
1397 | * |
||
1398 | * @param string $key |
||
1399 | * @param mixed $value |
||
1400 | * |
||
1401 | * @return bool |
||
1402 | */ |
||
1403 | 28 | protected function internalSet($key, $value) |
|
1431 | |||
1432 | /** |
||
1433 | * Return an array with all elements found in input array. |
||
1434 | * |
||
1435 | * @param array $search |
||
1436 | * |
||
1437 | * @return static (Immutable) |
||
1438 | */ |
||
1439 | 2 | public function intersection(array $search) |
|
1443 | |||
1444 | /** |
||
1445 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
1446 | * |
||
1447 | * @param array $search |
||
1448 | * |
||
1449 | * @return bool |
||
1450 | */ |
||
1451 | 1 | public function intersects(array $search) |
|
1455 | |||
1456 | /** |
||
1457 | * Invoke a function on all of an array's values. |
||
1458 | * |
||
1459 | * @param mixed $callable |
||
1460 | * @param mixed $arguments |
||
1461 | * |
||
1462 | * @return static (Immutable) |
||
1463 | */ |
||
1464 | 1 | public function invoke($callable, $arguments = array()) |
|
1480 | |||
1481 | /** |
||
1482 | * Check whether array is associative or not. |
||
1483 | * |
||
1484 | * @return bool Returns true if associative, false otherwise |
||
1485 | */ |
||
1486 | 15 | public function isAssoc() |
|
1500 | |||
1501 | /** |
||
1502 | * Check whether the array is empty or not. |
||
1503 | * |
||
1504 | * @return bool Returns true if empty, false otherwise |
||
1505 | */ |
||
1506 | 85 | public function isEmpty() |
|
1510 | |||
1511 | /** |
||
1512 | * Check if the current array is equal to the given "$array" or not. |
||
1513 | * |
||
1514 | * @param array $array |
||
1515 | * |
||
1516 | * @return bool |
||
1517 | */ |
||
1518 | public function isEqual(array $array) |
||
1522 | |||
1523 | /** |
||
1524 | * Check if the current array is a multi-array. |
||
1525 | * |
||
1526 | * @return bool |
||
1527 | */ |
||
1528 | 14 | public function isMultiArray() |
|
1532 | |||
1533 | /** |
||
1534 | * Check whether array is numeric or not. |
||
1535 | * |
||
1536 | * @return bool Returns true if numeric, false otherwise |
||
1537 | */ |
||
1538 | 5 | public function isNumeric() |
|
1552 | |||
1553 | /** |
||
1554 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
1555 | * |
||
1556 | * @return bool |
||
1557 | */ |
||
1558 | 1 | public function isSequential() |
|
1562 | |||
1563 | /** |
||
1564 | * Get all keys from the current array. |
||
1565 | * |
||
1566 | * @return static (Immutable) |
||
1567 | */ |
||
1568 | 25 | public function keys() |
|
1572 | |||
1573 | /** |
||
1574 | * Get the last value from the current array. |
||
1575 | * |
||
1576 | * @return mixed Return null if there wasn't a element. |
||
1577 | */ |
||
1578 | 4 | public function last() |
|
1582 | |||
1583 | /** |
||
1584 | * Get the last value(s) from the current array. |
||
1585 | * |
||
1586 | * @param int|null $number |
||
1587 | * |
||
1588 | * @return static (Immutable) |
||
1589 | */ |
||
1590 | 13 | public function lastsImmutable($number = null) |
|
1613 | |||
1614 | /** |
||
1615 | * Get the last value(s) from the current array. |
||
1616 | * |
||
1617 | * @param int|null $number |
||
1618 | * |
||
1619 | * @return static (Mutable) |
||
1620 | */ |
||
1621 | 13 | public function lastsMutable($number = null) |
|
1644 | |||
1645 | /** |
||
1646 | * Count the values from the current array. |
||
1647 | * |
||
1648 | * alias: for "Arrayy->size()" |
||
1649 | * |
||
1650 | * @see Arrayy::size() |
||
1651 | * |
||
1652 | * @return int |
||
1653 | */ |
||
1654 | 10 | public function length() |
|
1658 | |||
1659 | /** |
||
1660 | * Apply the given function to the every element of the array, |
||
1661 | * collecting the results. |
||
1662 | * |
||
1663 | * @param callable $callable |
||
1664 | * |
||
1665 | * @return static (Immutable) Arrayy object with modified elements |
||
1666 | */ |
||
1667 | 4 | public function map($callable) |
|
1673 | |||
1674 | /** |
||
1675 | * Check if all items in current array match a truth test. |
||
1676 | * |
||
1677 | * @param \Closure $closure |
||
1678 | * |
||
1679 | * @return bool |
||
1680 | */ |
||
1681 | 15 | View Code Duplication | public function matches(\Closure $closure) |
1700 | |||
1701 | /** |
||
1702 | * Check if any item in the current array matches a truth test. |
||
1703 | * |
||
1704 | * @param \Closure $closure |
||
1705 | * |
||
1706 | * @return bool |
||
1707 | */ |
||
1708 | 14 | View Code Duplication | public function matchesAny(\Closure $closure) |
1727 | |||
1728 | /** |
||
1729 | * Get the max value from an array. |
||
1730 | * |
||
1731 | * @return mixed |
||
1732 | */ |
||
1733 | 10 | public function max() |
|
1741 | |||
1742 | /** |
||
1743 | * Merge the new $array into the current array. |
||
1744 | * |
||
1745 | * - keep key,value from the current array, also if the index is in the new $array |
||
1746 | * |
||
1747 | * @param array $array |
||
1748 | * @param bool $recursive |
||
1749 | * |
||
1750 | * @return static (Immutable) |
||
1751 | */ |
||
1752 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = array(), $recursive = false) |
1762 | |||
1763 | /** |
||
1764 | * Merge the new $array into the current array. |
||
1765 | * |
||
1766 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
1767 | * - create new indexes |
||
1768 | * |
||
1769 | * @param array $array |
||
1770 | * @param bool $recursive |
||
1771 | * |
||
1772 | * @return static (Immutable) |
||
1773 | */ |
||
1774 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = array(), $recursive = false) |
1784 | |||
1785 | /** |
||
1786 | * Merge the the current array into the $array. |
||
1787 | * |
||
1788 | * - use key,value from the new $array, also if the index is in the current array |
||
1789 | * |
||
1790 | * @param array $array |
||
1791 | * @param bool $recursive |
||
1792 | * |
||
1793 | * @return static (Immutable) |
||
1794 | */ |
||
1795 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = array(), $recursive = false) |
1805 | |||
1806 | /** |
||
1807 | * Merge the current array into the new $array. |
||
1808 | * |
||
1809 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
1810 | * - create new indexes |
||
1811 | * |
||
1812 | * @param array $array |
||
1813 | * @param bool $recursive |
||
1814 | * |
||
1815 | * @return static (Immutable) |
||
1816 | */ |
||
1817 | 16 | View Code Duplication | public function mergePrependNewIndex(array $array = array(), $recursive = false) |
1827 | |||
1828 | /** |
||
1829 | * Get the min value from an array. |
||
1830 | * |
||
1831 | * @return mixed |
||
1832 | */ |
||
1833 | 10 | public function min() |
|
1841 | |||
1842 | /** |
||
1843 | * Get a subset of the items from the given array. |
||
1844 | * |
||
1845 | * @param mixed[] $keys |
||
1846 | * |
||
1847 | * @return static (Immutable) |
||
1848 | */ |
||
1849 | public function only(array $keys) |
||
1855 | |||
1856 | /** |
||
1857 | * Pad array to the specified size with a given value. |
||
1858 | * |
||
1859 | * @param int $size Size of the result array |
||
1860 | * @param mixed $value Empty value by default |
||
1861 | * |
||
1862 | * @return static (Immutable) Arrayy object padded to $size with $value |
||
1863 | */ |
||
1864 | 4 | public function pad($size, $value) |
|
1870 | |||
1871 | /** |
||
1872 | * Pop a specified value off the end of the current array. |
||
1873 | * |
||
1874 | * @return mixed The popped element from the current array. (Mutable) |
||
1875 | */ |
||
1876 | 16 | public function pop() |
|
1880 | |||
1881 | /** |
||
1882 | * Prepend a value to the current array. |
||
1883 | * |
||
1884 | * @param mixed $value |
||
1885 | * @param mixed $key |
||
1886 | * |
||
1887 | * @return static (Mutable) Return this Arrayy object, with the prepended value. |
||
1888 | */ |
||
1889 | 8 | public function prepend($value, $key = null) |
|
1900 | |||
1901 | /** |
||
1902 | * Push one or more values onto the end of array at once. |
||
1903 | * |
||
1904 | * @return static (Mutable) Return this Arrayy object, with pushed elements to the end of array. |
||
1905 | */ |
||
1906 | 4 | View Code Duplication | public function push(/* variadic arguments allowed */) |
1915 | |||
1916 | /** |
||
1917 | * Get a random value from the current array. |
||
1918 | * |
||
1919 | * @param null|int $number how many values you will take? |
||
1920 | * |
||
1921 | * @return static (Immutable) |
||
1922 | */ |
||
1923 | 17 | public function randomImmutable($number = null) |
|
1940 | |||
1941 | /** |
||
1942 | * Pick a random key/index from the keys of this array. |
||
1943 | * |
||
1944 | * @return mixed get a key/index or null if there wasn't a key/index |
||
1945 | * |
||
1946 | * @throws \RangeException If array is empty |
||
1947 | */ |
||
1948 | 4 | public function randomKey() |
|
1958 | |||
1959 | /** |
||
1960 | * Pick a given number of random keys/indexes out of this array. |
||
1961 | * |
||
1962 | * @param int $number The number of keys/indexes (should be <= $this->count()) |
||
1963 | * |
||
1964 | * @return static (Immutable) |
||
1965 | * |
||
1966 | * @throws \RangeException If array is empty |
||
1967 | */ |
||
1968 | 14 | public function randomKeys($number) |
|
1987 | |||
1988 | /** |
||
1989 | * Get a random value from the current array. |
||
1990 | * |
||
1991 | * @param null|int $number how many values you will take? |
||
1992 | * |
||
1993 | * @return static (Mutable) |
||
1994 | */ |
||
1995 | 17 | public function randomMutable($number = null) |
|
2012 | |||
2013 | /** |
||
2014 | * Pick a random value from the values of this array. |
||
2015 | * |
||
2016 | * @return mixed get a random value or null if there wasn't a value |
||
2017 | */ |
||
2018 | 4 | public function randomValue() |
|
2028 | |||
2029 | /** |
||
2030 | * Pick a given number of random values out of this array. |
||
2031 | * |
||
2032 | * @param int $number |
||
2033 | * |
||
2034 | * @return static (Mutable) |
||
2035 | */ |
||
2036 | 7 | public function randomValues($number) |
|
2042 | |||
2043 | /** |
||
2044 | * Get a random value from an array, with the ability to skew the results. |
||
2045 | * |
||
2046 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
2047 | * |
||
2048 | * @param array $array |
||
2049 | * @param null|int $number how many values you will take? |
||
2050 | * |
||
2051 | * @return static (Immutable) |
||
2052 | */ |
||
2053 | 9 | public function randomWeighted(array $array, $number = null) |
|
2066 | |||
2067 | /** |
||
2068 | * Reduce the current array via callable e.g. anonymous-function. |
||
2069 | * |
||
2070 | * @param mixed $callable |
||
2071 | * @param array $init |
||
2072 | * |
||
2073 | * @return static (Immutable) |
||
2074 | */ |
||
2075 | 3 | public function reduce($callable, array $init = array()) |
|
2087 | |||
2088 | /** |
||
2089 | * Create a numerically re-indexed Arrayy object. |
||
2090 | * |
||
2091 | * @return static (Mutable) Return this Arrayy object, with re-indexed array-elements. |
||
2092 | */ |
||
2093 | 9 | public function reindex() |
|
2099 | |||
2100 | /** |
||
2101 | * Return all items that fail the truth test. |
||
2102 | * |
||
2103 | * @param \Closure $closure |
||
2104 | * |
||
2105 | * @return static (Immutable) |
||
2106 | */ |
||
2107 | 1 | View Code Duplication | public function reject(\Closure $closure) |
2119 | |||
2120 | /** |
||
2121 | * Remove a value from the current array (optional using dot-notation). |
||
2122 | * |
||
2123 | * @param mixed $key |
||
2124 | * |
||
2125 | * @return static (Immutable) |
||
2126 | */ |
||
2127 | 18 | public function remove($key) |
|
2142 | |||
2143 | /** |
||
2144 | * Remove the first value from the current array. |
||
2145 | * |
||
2146 | * @return static (Immutable) |
||
2147 | */ |
||
2148 | 7 | public function removeFirst() |
|
2155 | |||
2156 | /** |
||
2157 | * Remove the last value from the current array. |
||
2158 | * |
||
2159 | * @return static (Immutable) |
||
2160 | */ |
||
2161 | 7 | public function removeLast() |
|
2168 | |||
2169 | /** |
||
2170 | * Removes a particular value from an array (numeric or associative). |
||
2171 | * |
||
2172 | * @param mixed $value |
||
2173 | * |
||
2174 | * @return static (Immutable) |
||
2175 | */ |
||
2176 | 7 | public function removeValue($value) |
|
2194 | |||
2195 | /** |
||
2196 | * Replace a key with a new key/value pair. |
||
2197 | * |
||
2198 | * @param $replace |
||
2199 | * @param $key |
||
2200 | * @param $value |
||
2201 | * |
||
2202 | * @return static (Immutable) |
||
2203 | */ |
||
2204 | 2 | public function replace($replace, $key, $value) |
|
2210 | |||
2211 | /** |
||
2212 | * Create an array using the current array as values and the other array as keys. |
||
2213 | * |
||
2214 | * @param array $keys Keys array |
||
2215 | * |
||
2216 | * @return static (Immutable) Arrayy object with keys from the other array. |
||
2217 | */ |
||
2218 | 2 | public function replaceAllKeys(array $keys) |
|
2224 | |||
2225 | /** |
||
2226 | * Create an array using the current array as keys and the other array as values. |
||
2227 | * |
||
2228 | * @param array $array Values array |
||
2229 | * |
||
2230 | * @return static (Immutable) Arrayy object with values from the other array. |
||
2231 | */ |
||
2232 | 2 | public function replaceAllValues(array $array) |
|
2238 | |||
2239 | /** |
||
2240 | * Replace the keys in an array with another set. |
||
2241 | * |
||
2242 | * @param array $keys An array of keys matching the array's size |
||
2243 | * |
||
2244 | * @return static (Immutable) |
||
2245 | */ |
||
2246 | 1 | public function replaceKeys(array $keys) |
|
2253 | |||
2254 | /** |
||
2255 | * Replace the first matched value in an array. |
||
2256 | * |
||
2257 | * @param mixed $search |
||
2258 | * @param mixed $replacement |
||
2259 | * |
||
2260 | * @return static (Immutable) |
||
2261 | */ |
||
2262 | 3 | public function replaceOneValue($search, $replacement = '') |
|
2273 | |||
2274 | /** |
||
2275 | * Replace values in the current array. |
||
2276 | * |
||
2277 | * @param string $search The string to replace. |
||
2278 | * @param string $replacement What to replace it with. |
||
2279 | * |
||
2280 | * @return static (Immutable) |
||
2281 | */ |
||
2282 | 1 | public function replaceValues($search, $replacement = '') |
|
2292 | |||
2293 | /** |
||
2294 | * Get the last elements from index $from until the end of this array. |
||
2295 | * |
||
2296 | * @param int $from |
||
2297 | * |
||
2298 | * @return static (Immutable) |
||
2299 | */ |
||
2300 | 15 | public function rest($from = 1) |
|
2306 | |||
2307 | /** |
||
2308 | * Move an array element to a new index. |
||
2309 | * |
||
2310 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
2311 | * |
||
2312 | * @param int|string $from |
||
2313 | * @param int|string $to |
||
2314 | * |
||
2315 | * @return static (Immutable) |
||
2316 | */ |
||
2317 | 1 | public function moveElement($from, $to) |
|
2344 | |||
2345 | /** |
||
2346 | * Return the array in the reverse order. |
||
2347 | * |
||
2348 | * @return static (Mutable) Return this Arrayy object. |
||
2349 | */ |
||
2350 | 7 | public function reverse() |
|
2356 | |||
2357 | /** |
||
2358 | * Search for the first index of the current array via $value. |
||
2359 | * |
||
2360 | * @param mixed $value |
||
2361 | * |
||
2362 | * @return int|float|string |
||
2363 | */ |
||
2364 | 20 | public function searchIndex($value) |
|
2368 | |||
2369 | /** |
||
2370 | * Search for the value of the current array via $index. |
||
2371 | * |
||
2372 | * @param mixed $index |
||
2373 | * |
||
2374 | * @return static (Immutable) will return a empty Arrayy if the value wasn't found |
||
2375 | */ |
||
2376 | 9 | public function searchValue($index) |
|
2397 | |||
2398 | /** |
||
2399 | * Set a value for the current array (optional using dot-notation). |
||
2400 | * |
||
2401 | * @param string $key The key to set |
||
2402 | * @param mixed $value Its value |
||
2403 | * |
||
2404 | * @return static (Immutable) |
||
2405 | */ |
||
2406 | 17 | public function set($key, $value) |
|
2412 | |||
2413 | /** |
||
2414 | * Get a value from a array and set it if it was not. |
||
2415 | * |
||
2416 | * WARNING: this method only set the value, if the $key is not already set |
||
2417 | * |
||
2418 | * @param string $key The key |
||
2419 | * @param mixed $fallback The default value to set if it isn't |
||
2420 | * |
||
2421 | * @return mixed (Mutable) |
||
2422 | */ |
||
2423 | 11 | public function setAndGet($key, $fallback = null) |
|
2432 | |||
2433 | /** |
||
2434 | * Shifts a specified value off the beginning of array. |
||
2435 | * |
||
2436 | * @return mixed A shifted element from the current array. (Mutable) |
||
2437 | */ |
||
2438 | 4 | public function shift() |
|
2442 | |||
2443 | /** |
||
2444 | * Shuffle the current array. |
||
2445 | * |
||
2446 | * @return static (Immutable) |
||
2447 | */ |
||
2448 | 1 | public function shuffle() |
|
2456 | |||
2457 | /** |
||
2458 | * Get the size of an array. |
||
2459 | * |
||
2460 | * @return int |
||
2461 | */ |
||
2462 | 93 | public function size() |
|
2466 | |||
2467 | /** |
||
2468 | * Extract a slice of the array. |
||
2469 | * |
||
2470 | * @param int $offset Slice begin index |
||
2471 | * @param int|null $length Length of the slice |
||
2472 | * @param bool $preserveKeys Whether array keys are preserved or no |
||
2473 | * |
||
2474 | * @return static A slice of the original array with length $length |
||
2475 | */ |
||
2476 | 4 | public function slice($offset, $length = null, $preserveKeys = false) |
|
2482 | |||
2483 | /** |
||
2484 | * Sort the current array and optional you can keep the keys. |
||
2485 | * |
||
2486 | * @param integer $direction use SORT_ASC or SORT_DESC |
||
2487 | * @param integer $strategy |
||
2488 | * @param bool $keepKeys |
||
2489 | * |
||
2490 | * @return static (Mutable) Return this Arrayy object. |
||
2491 | */ |
||
2492 | 19 | public function sort($direction = SORT_ASC, $strategy = SORT_REGULAR, $keepKeys = false) |
|
2498 | |||
2499 | /** |
||
2500 | * Sort the current array by key. |
||
2501 | * |
||
2502 | * @link http://php.net/manual/en/function.ksort.php |
||
2503 | * @link http://php.net/manual/en/function.krsort.php |
||
2504 | * |
||
2505 | * @param int|string $direction use SORT_ASC or SORT_DESC |
||
2506 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
2507 | * |
||
2508 | * @return static (Mutable) Return this Arrayy object. |
||
2509 | */ |
||
2510 | 18 | public function sortKeys($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
2516 | |||
2517 | /** |
||
2518 | * Sort the current array by value. |
||
2519 | * |
||
2520 | * @param int $direction use SORT_ASC or SORT_DESC |
||
2521 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
2522 | * |
||
2523 | * @return static (Immutable) |
||
2524 | */ |
||
2525 | 1 | public function sortValueKeepIndex($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
2529 | |||
2530 | /** |
||
2531 | * Sort the current array by value. |
||
2532 | * |
||
2533 | * @param int $direction use SORT_ASC or SORT_DESC |
||
2534 | * @param int $strategy use e.g.: SORT_REGULAR or SORT_NATURAL |
||
2535 | * |
||
2536 | * @return static (Immutable) |
||
2537 | */ |
||
2538 | 1 | public function sortValueNewIndex($direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
2542 | |||
2543 | /** |
||
2544 | * Sort a array by value, by a closure or by a property. |
||
2545 | * |
||
2546 | * - If the sorter is null, the array is sorted naturally. |
||
2547 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
2548 | * |
||
2549 | * @param null $sorter |
||
2550 | * @param string|int $direction |
||
2551 | * @param int $strategy |
||
2552 | * |
||
2553 | * @return static (Immutable) |
||
2554 | */ |
||
2555 | 1 | public function sorter($sorter = null, $direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
2581 | |||
2582 | /** |
||
2583 | * sorting keys |
||
2584 | * |
||
2585 | * @param array $elements |
||
2586 | * @param int $direction |
||
2587 | * @param int $strategy |
||
2588 | */ |
||
2589 | 18 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, $strategy = SORT_REGULAR) |
|
2604 | |||
2605 | /** |
||
2606 | * @param array &$elements |
||
2607 | * @param int|string $direction |
||
2608 | * @param int $strategy |
||
2609 | * @param bool $keepKeys |
||
2610 | */ |
||
2611 | 19 | protected function sorting(array &$elements, $direction = SORT_ASC, $strategy = SORT_REGULAR, $keepKeys = false) |
|
2638 | |||
2639 | /** |
||
2640 | * Split an array in the given amount of pieces. |
||
2641 | * |
||
2642 | * @param int $numberOfPieces |
||
2643 | * @param bool $keepKeys |
||
2644 | * |
||
2645 | * @return static (Immutable) |
||
2646 | */ |
||
2647 | 1 | public function split($numberOfPieces = 2, $keepKeys = false) |
|
2661 | |||
2662 | /** |
||
2663 | * Stripe all empty items. |
||
2664 | * |
||
2665 | * @return static (Immutable) |
||
2666 | */ |
||
2667 | 1 | public function stripEmpty() |
|
2679 | |||
2680 | /** |
||
2681 | * Swap two values between positions by key. |
||
2682 | * |
||
2683 | * @param string|int $swapA an key in the array |
||
2684 | * @param string|int $swapB an key in the array |
||
2685 | * |
||
2686 | * @return static (Immutable) |
||
2687 | */ |
||
2688 | 1 | public function swap($swapA, $swapB) |
|
2696 | |||
2697 | /** |
||
2698 | * alias: for "Arrayy->getArray()" |
||
2699 | * |
||
2700 | * @see Arrayy::getArray() |
||
2701 | */ |
||
2702 | 141 | public function toArray() |
|
2706 | |||
2707 | /** |
||
2708 | * Convert the current array to JSON. |
||
2709 | * |
||
2710 | * @param null $options e.g. JSON_PRETTY_PRINT |
||
2711 | * |
||
2712 | * @return string |
||
2713 | */ |
||
2714 | 5 | public function toJson($options = null) |
|
2718 | |||
2719 | /** |
||
2720 | * Implodes array to a string with specified separator. |
||
2721 | * |
||
2722 | * @param string $separator The element's separator |
||
2723 | * |
||
2724 | * @return string The string representation of array, separated by "," |
||
2725 | */ |
||
2726 | 19 | public function toString($separator = ',') |
|
2730 | |||
2731 | /** |
||
2732 | * alias: for "Arrayy->unique()" |
||
2733 | * |
||
2734 | * @see Arrayy::unique() |
||
2735 | * |
||
2736 | 8 | * @return static (Mutable) Return this Arrayy object, with the appended values. |
|
2737 | */ |
||
2738 | 8 | public function uniqueKeepIndex() |
|
2742 | 7 | ||
2743 | 7 | /** |
|
2744 | * Return a duplicate free copy of the current array. |
||
2745 | 7 | * |
|
2746 | 8 | * @return static (Mutable) |
|
2747 | 8 | */ |
|
2748 | 8 | public function unique() |
|
2770 | |||
2771 | 4 | /** |
|
2772 | * Prepends one or more values to the beginning of array at once. |
||
2773 | * |
||
2774 | * @return static (Mutable) Return this Arrayy object, with prepended elements to the beginning of array. |
||
2775 | */ |
||
2776 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
|
2785 | |||
2786 | /** |
||
2787 | * Get all values from a array. |
||
2788 | * |
||
2789 | * @return static (Immutable) |
||
2790 | */ |
||
2791 | public function values() |
||
2795 | 4 | ||
2796 | 4 | /** |
|
2797 | 5 | * Apply the given function to every element in the array, discarding the results. |
|
2798 | * |
||
2799 | * @param callable $callable |
||
2800 | 9 | * @param bool $recursive Whether array will be walked recursively or no |
|
2801 | * |
||
2802 | * @return static (Mutable) Return this Arrayy object, with modified elements |
||
2803 | */ |
||
2804 | public function walk($callable, $recursive = false) |
||
2814 | |||
2815 | } |
||
2816 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.