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.

Arr::only()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spatie\DataTransferObject;
6
7
use ArrayAccess;
8
9
class Arr
10
{
11
    public static function only($array, $keys): array
12
    {
13
        return array_intersect_key($array, array_flip((array) $keys));
14
    }
15
16
    public static function except($array, $keys): array
17
    {
18
        return static::forget($array, $keys);
19
    }
20
21
    public static function forget($array, $keys): array
22
    {
23
        $keys = (array) $keys;
24
25
        if (count($keys) === 0) {
26
            return $array;
27
        }
28
29
        foreach ($keys as $key) {
30
            // If the exact key exists in the top-level, remove it
31
            if (static::exists($array, $key)) {
32
                unset($array[$key]);
33
34
                continue;
35
            }
36
37
            $parts = explode('.', $key);
38
39
            while (count($parts) > 1) {
40
                $part = array_shift($parts);
41
42
                if (isset($array[$part]) && is_array($array[$part])) {
43
                    $array = &$array[$part];
44
                } else {
45
                    continue 2;
46
                }
47
            }
48
49
            unset($array[array_shift($parts)]);
50
        }
51
52
        return $array;
53
    }
54
55
    public static function exists($array, $key): bool
56
    {
57
        if ($array instanceof ArrayAccess) {
58
            return $array->offsetExists($key);
59
        }
60
61
        return array_key_exists($key, $array);
62
    }
63
}
64