Arr::isAssoc()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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