Passed
Pull Request — master (#35)
by
unknown
12:58
created

Arrays   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unique() 0 6 1
A flatten() 0 4 1
1
<?php
2
3
namespace TestMonitor\DevOps\Support;
4
5
class Arrays
6
{
7
    /**
8
     * Flatten a multi-dimensional associative array.
9
     *
10
     * @param array $array
11
     * @return array
12
     */
13
    public static function flatten(array $array): array
14
    {
15
        return array_merge(
16
            ...array_values($array)
17
        );
18
    }
19
20
    /**
21
     * Takes an associative array and returns a new array without duplicate items.
22
     *
23
     * @param array $array
24
     * @return array
25
     */
26
    public static function unique(array $array, string $field)
27
    {
28
        return array_intersect_key(
29
            $array,
30
            array_unique(
31
                array_column($array, $field)
32
            )
33
        );
34
    }
35
}
36