ArrayHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A flatten() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Schemator\Helpers;
6
7
/**
8
 * @internal
9
 */
10
class ArrayHelper
11
{
12
    /**
13
     * Flattens an array.
14
     *
15
     * @param array<mixed> $input array to flatten
16
     *
17
     * @return array<scalar|object> flat array
18
     */
19
    public static function flatten(array $input): array
20
    {
21
        $tmp = [];
22
        foreach ($input as $val) {
23
            if (is_array($val)) {
24
                $tmp = array_merge($tmp, static::flatten($val));
25
            } else {
26
                $tmp[] = $val;
27
            }
28
        }
29
30
        return $tmp;
31
    }
32
}
33