ArrayUtility   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A flatten() 0 15 5
1
<?php
2
declare(strict_types = 1);
3
namespace T3G\Elasticorn\Utility;
4
5
6
/**
7
 * Class ArrayUtility
8
 *
9
 * @package T3G\Elasticorn\Utility
10
 */
11
class ArrayUtility
12
{
13
14
    /**
15
     * @param array $array
16
     * @param string $prefix
17
     * @return array
18
     */
19
    public static function flatten(array $array, string $prefix = '') : array
20
    {
21
        $result = [];
22
        foreach ($array as $key => $value) {
23
            if ($prefix) {
24
                $key = $prefix . '.' . $key;
25
            }
26
            if (is_array($value)) {
27
                $result = array_merge($result, self::flatten($value, (string)$key));
28
            } else {
29
                $result[$key] = is_scalar($value) ? $value : gettype($value);
30
            }
31
        }
32
        return $result;
33
    }
34
}