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

Arrays::flatten()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
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