1 | <?php |
||
8 | class Enumerator |
||
9 | { |
||
10 | use SplitPathTrait; |
||
11 | use ValueTrait; |
||
12 | |||
13 | /** |
||
14 | * Return the first element in an array passing a given truth test. |
||
15 | * |
||
16 | * @param array $array |
||
17 | * @param callable $callback |
||
18 | * @param mixed $default |
||
19 | * |
||
20 | * @return mixed |
||
21 | */ |
||
22 | public function first(array $array, callable $callback, $default = null) |
||
32 | |||
33 | /** |
||
34 | * Return the last element in an array passing a given truth test. |
||
35 | * |
||
36 | * @param array $array |
||
37 | * @param callable $callback |
||
38 | * @param mixed $default |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function last(array $array, callable $callback, $default = null) |
||
46 | |||
47 | /** |
||
48 | * Get a random element from the array supplied. |
||
49 | * |
||
50 | * @param array $array the source array |
||
51 | * |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public static function random(array $array) |
||
64 | |||
65 | /** |
||
66 | * Get a subset of the items from the given array. |
||
67 | * |
||
68 | * @param string[] $array |
||
69 | * @param string[] $keys |
||
70 | * |
||
71 | * @return string[] |
||
72 | */ |
||
73 | public function only(array $array, $keys) |
||
77 | |||
78 | /** |
||
79 | * Split an array in the given amount of pieces. |
||
80 | * |
||
81 | * @param array $array |
||
82 | * @param int $numberOfPieces |
||
83 | * @param bool $preserveKeys |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function split(array $array, $numberOfPieces = 2, $preserveKeys = false) |
||
97 | |||
98 | /** |
||
99 | * Pluck an array of values from an array. |
||
100 | * |
||
101 | * @param array|\ArrayAccess $array |
||
102 | * @param string $value |
||
103 | * @param string|null $key |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function pluck(array $array, $value, $key = null) |
||
128 | |||
129 | /** |
||
130 | * Filter the array using the given Closure. |
||
131 | * |
||
132 | * @param array $array |
||
133 | * @param callable $callback |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | public function where(array $array, callable $callback) |
||
149 | |||
150 | /** |
||
151 | * Push an item onto the beginning of an array. |
||
152 | * |
||
153 | * @param array $array |
||
154 | * @param mixed $value |
||
155 | * @param mixed $key |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function prepend(array $array, $value, $key = null) |
||
169 | |||
170 | /** |
||
171 | * Get an item from an array or object using "dot" notation. |
||
172 | * |
||
173 | * @param mixed $target |
||
174 | * @param string|array $key |
||
175 | * @param string $default |
||
176 | * |
||
177 | * @return mixed |
||
178 | */ |
||
179 | public function dataGet($target, $key, $default = null) |
||
223 | |||
224 | /** |
||
225 | * Replace a given pattern with each value in the array in sequentially. |
||
226 | * |
||
227 | * @param string $pattern |
||
228 | * @param array $replacements |
||
229 | * @param string $subject |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | public function pregReplaceSub($pattern, &$replacements, $subject) |
||
239 | |||
240 | /** |
||
241 | * A shorter way to run a match on the array's keys rather than the values. |
||
242 | * |
||
243 | * @param string $pattern |
||
244 | * @param array $input |
||
245 | * @param int $flags |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | public function pregGrepKeys($pattern, array $input, $flags = 0) |
||
253 | |||
254 | /** |
||
255 | * Explode the "value" and "key" arguments passed to "pluck". |
||
256 | * |
||
257 | * @param string $value |
||
258 | * @param string|null $key |
||
259 | * |
||
260 | * @return array[] |
||
261 | */ |
||
262 | protected function explodePluckParameters($value, $key) |
||
270 | } |
||
271 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.