Passed
Pull Request — master (#23)
by Thijs
05:42
created

Arrays   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 29
rs 10
c 1
b 0
f 0
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
     *
12
     * @return array
13
     */
14
    public static function flatten(array $array): array
15
    {
16
        return array_merge(
17
            ...array_values($array)
18
        );
19
    }
20
21
    /**
22
     * Takes an associative array and returns a new array without duplicate items.
23
     *
24
     * @param array $array
25
     *
26
     * @return array
27
     */
28
    public static function unique(array $array, string $field)
29
    {
30
        return array_intersect_key(
31
            $array,
32
            array_unique(
33
                array_column($array, $field)
34
            )
35
        );
36
    }
37
}
38