Completed
Push — master ( 3442f8...f4ff57 )
by Vladimir
02:32
created

ArrayUtilities   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 20
cts 25
cp 0.8
rs 10
c 0
b 0
f 0
wmc 13
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A is_multidimensional() 0 12 3
D array_merge_defaults() 0 46 10
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Utilities;
9
10
abstract class ArrayUtilities
0 ignored issues
show
Coding Style introduced by
ArrayUtilities does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
11
{
12 6
    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...
Coding Style introduced by
function is_multidimensional() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
13
    {
14 6
        foreach ($array as $element)
15
        {
16 6
            if (is_array($element))
17
            {
18 1
                return true;
19
            }
20
        }
21
22 5
        return false;
23
    }
24
25 30
    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...
Coding Style introduced by
function array_merge_defaults() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
26
    {
27 30
        $merged = $array1;
28
29 30
        foreach ($array2 as $key => &$value)
30
        {
31 2
            $valueMerged = false;
32
33 2
            foreach ($merged as $mergedKey => &$item)
34
            {
35 2
                if (is_array($item) && array_key_exists($keyField, $item) && $item[$keyField] == $value[$keyField])
36
                {
37
                    $item = array_merge($item, $value);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
38
                    $valueMerged = true;
39
40
                    break;
41
                }
42 2
                elseif ($mergedKey == $key)
43
                {
44 1
                    if (is_numeric($mergedKey))
45
                    {
46
                        $merged[] = $value;
47
                    }
48 1
                    elseif (is_array($item))
49
                    {
50
                        $item = array_unique(array_merge($item, $value));
51
                    }
52
                    else
53
                    {
54 1
                        $item = $value;
55
                    }
56
57 1
                    $valueMerged = true;
58
59 1
                    break;
60
                }
61
            }
62
63 2
            if (!$valueMerged)
64
            {
65 2
                $merged[$key] = $value;
66
            }
67
        }
68
69 30
        return $merged;
70
    }
71
}
72