Completed
Push — master ( d40022...a8a6e5 )
by Arne
01:50
created

ArrayUtils   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C recursiveArrayDiff() 0 30 7
1
<?php
2
3
namespace Archivr;
4
5
abstract class ArrayUtils
6
{
7
    /**
8
     * @see http://php.net/manual/en/function.array-diff.php#91756
9
     * @param array $array1
10
     * @param array $array2
11
     * @return array
12
     */
13
    public static function recursiveArrayDiff(array $array1, array $array2): array
14
    {
15
        $return = [];
16
17
        foreach ($array1 as $key => $value)
18
        {
19
            if (array_key_exists($key, $array2))
20
            {
21
                if (is_array($value) && is_array($array2[$key]))
22
                {
23
                    $recursiveDiff = static::recursiveArrayDiff($value, $array2[$key]);
24
25
                    if (count($recursiveDiff))
26
                    {
27
                        $return[$key] = $recursiveDiff;
28
                    }
29
                }
30
                elseif ($value !== $array2[$key])
31
                {
32
                    $return[$key] = $value;
33
                }
34
            }
35
            else
36
            {
37
                $return[$key] = $value;
38
            }
39
        }
40
41
        return $return;
42
    }
43
}
44