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

Arrays::unique()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
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
     * @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