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

Arrays   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 27
ccs 9
cts 9
cp 1
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
     * @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