GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#36)
by Sebastian
02:03
created

Arr::flatMap()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 2
1
<?php
2
3
namespace Spatie\OpeningHours\Helpers;
4
5
class Arr
6
{
7
    public static function map(array $array, callable $callback): array
8
    {
9
        $keys = array_keys($array);
10
11
        $items = array_map($callback, $array, $keys);
12
13
        return array_combine($keys, $items);
14
    }
15
16
    public static function flatMap(array $array, callable $callback): array
17
    {
18
        $mapped = self::map($array, $callback);
19
20
        $flattened = [];
21
22
        foreach ($mapped as $item) {
23
            if (is_array($item)) {
24
                $flattened = array_merge($flattened, $item);
25
            } else {
26
                $flattened[] = $item;
27
            }
28
        }
29
30
        return $flattened;
31
    }
32
33
    public static function pull(&$array, $key, $default = null)
34
    {
35
        $value = $array[$key] ?? $default;
36
37
        unset($array[$key]);
38
39
        return $value;
40
    }
41
42
    public static function mirror(array $array): array
43
    {
44
        return array_combine($array, $array);
45
    }
46
47
    public static function createUniquePairs(array $array): array
48
    {
49
        $pairs = [];
50
51
        while ($a = array_shift($array)) {
52
            foreach ($array as $b) {
53
                $pairs[] = [$a, $b];
54
            }
55
        }
56
57
        return $pairs;
58
    }
59
}
60