The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see
which comment annotations we can parse, please refer to our documentation on
supported doc-types.
Loading history...
15
*/
16
public function map(array $array, callable $callback)
17
{
18
$newArray = [];
19
20
foreach ($array as $key => $item) {
21
$result = call_user_func($callback, $item, $key);
22
23
$newArray = is_array($result) ?
24
array_replace_recursive($array, $result) :
25
array_merge_recursive($array, (array) $result);
26
}
27
28
return $newArray;
29
}
30
31
/**
32
* Filters each of the given values through a function.
33
*
34
* @param array $array
35
* @param callable $callback
36
*
37
* @return array
38
*/
39
public function filter(array $array, callable $callback)
40
{
41
$newArray = [];
42
43
foreach ($array as $key => $item) {
44
if (call_user_func($callback, $item, $key)) {
45
$newArray[$key] = $item;
46
}
47
}
48
49
return $newArray;
50
}
51
52
/**
53
* The opposite of filter().
54
*
55
* @param array $array
56
* @param callable $cb Function to filter values.
57
*
58
* @return array filtered array.
59
*/
60
public static function reject(array $array, callable $cb)
Avoid variables with short names like $cb. Configured minimum length is 3.
Short variable names may make your code harder to understand. Variable names should
be self-descriptive. This check looks for variable names who are shorter than
a configured minimum.
Loading history...
61
{
62
return $this->filter($array, function ($value, $key) use ($cb) {
The variable $this does not exist. Did you forget to declare it?
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.
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.