Passed
Push — master ( f519e1...ef65fe )
by Brian
02:51
created

Arr::isAssoc()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Bmatovu\Ussd\Support;
4
5
class Arr
6
{
7
    /**
8
     * @see https://stackoverflow.com/a/173479/2732184
9
     */
10
    public static function isAssoc(array $arr): bool
11
    {
12
        if ([] === $arr) {
13
            return false;
14
        }
15
16
        return array_keys($arr) !== range(0, \count($arr) - 1);
17
    }
18
19
    public static function keysDiff(array $required, array $given): array
20
    {
21
        if (self::isAssoc($given)) {
22
            $given = array_keys($given);
23
        }
24
25
        return array_diff($required, $given);
26
    }
27
}
28