Completed
Push — master ( 2f45a4...5d8b59 )
by Thijs
15s queued 14s
created

Arrays::unique()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
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 3
    public static function flatten(array $array): array
14
    {
15 3
        return array_merge(
16 3
            ...array_values($array)
17 3
        );
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 2
    public static function unique(array $array, string $field)
27
    {
28 2
        return array_intersect_key(
29 2
            $array,
30 2
            array_unique(
31 2
                array_column($array, $field)
32 2
            )
33 2
        );
34
    }
35
}
36