Completed
Pull Request — master (#20)
by Vladimir
02:43
created

ArrayUtilities::is_multidimensional()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
1
<?php
2
3
namespace allejo\stakx\Utilities;
4
5
abstract class ArrayUtilities
6
{
7 4
    public static function is_multidimensional (array &$array)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
8
    {
9 4
        foreach ($array as $element)
10
        {
11 4
            if (is_array($element))
12 4
                return true;
13 3
        }
14
15 3
        return false;
16
    }
17
    
18 16
    public static function array_merge_defaults (array &$array1, array &$array2, $keyField)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
19
    {
20 16
        $merged = $array1;
21
22 16
        foreach ($array2 as $key => &$value)
23
        {
24 16
            $valueMerged = false;
25
26 16
            foreach ($merged as $mergedKey => &$item)
27
            {
28 16
                if (is_array($item) && array_key_exists($keyField, $item) && $item[$keyField] == $value[$keyField])
29 16
                {
30
                    $item = array_merge($item, $value);
31
                    $valueMerged = true;
32
33
                    break;
34
                }
35 16
                else if ($mergedKey == $key)
36 16
                {
37 15
                    if (is_numeric($mergedKey))
38 15
                    {
39
                        $merged[] = $value;
40
                    }
41 15
                    else if (is_array($item))
42 15
                    {
43 15
                        $item = array_unique(array_merge($item, $value));
44 15
                    }
45
                    else
46
                    {
47 15
                        $item = $value;
48
                    }
49
50 15
                    $valueMerged = true;
51
52 15
                    break;
53
                }
54 16
            }
55
56 16
            if (!$valueMerged)
57 16
            {
58 16
                $merged[$key] = $value;
59 16
            }
60 16
        }
61
62 16
        return $merged;
63
    }
64
}