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.

functions.php ➔ options_merge()   C
last analyzed

Complexity

Conditions 15
Paths 153

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 15.225

Importance

Changes 0
Metric Value
cc 15
nc 153
nop 2
dl 0
loc 55
ccs 27
cts 30
cp 0.9
crap 15.225
rs 5.475
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation;
4
5
/**
6
 * @param  array $base
7
 * @param  array $options
8
 * @return array
9
 */
10
function options_merge(array $base, array $options): array
11
{
12 5
    $merge = true;
13 5
    foreach ($base as $key => $value) {
14 2
        if (is_numeric($key)) {
15 2
            $merge = false;
16
        }
17
    }
18 5
    foreach ($options as $name => $option) {
19 4
        if (is_numeric($name)) {
20 4
            $merge = false;
21
        }
22
    }
23
24 5
    if ($merge === false) {
25 2
        $new = [];
26
27 2
        foreach ($base as $key => $value) {
28 2
            if (in_array($value, $new, true)) {
29
                continue;
30
            }
31 2
            $new[] = $value;
32
        }
33 2
        foreach ($options as $name => $option) {
34 2
            if (in_array($option, $new, true)) {
35 1
                continue;
36
            }
37 1
            $new[] = $option;
38
        }
39
40 2
        return $new;
41
    }
42
43 5
    foreach ($base as $key => $value) {
44 2
        if (!isset($options[$key])) {
45
            continue;
46
        }
47
48 2
        $option = $options[$key];
49 2
        unset($options[$key]);
50
51 2
        if (is_array($value) && is_array($option)) {
52 2
            $base[$key] = options_merge($value, $option);
53 2
            continue;
54
        }
55
56
        $base[$key] = $option;
57
    }
58
59 5
    foreach ($options as $name => $option) {
60 4
        $base[$name] = $option;
61
    }
62
63 5
    return $base;
64
}
65