ArrayUtils::flatArrayRecursive()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 9
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Utils;
6
7
class ArrayUtils
8
{
9
    /**
10
     * @param null|array $array
11
     *
12
     * @return array
13
     */
14 19
    public static function flatArrayRecursive(?array $array): array
15
    {
16 19
        if (empty($array)) {
17 1
            return [];
18
        }
19
20 19
        $resultArray = [];
21
22 19
        foreach ($array as $key => $value) {
23 19
            if (\is_array($value)) {
24 19
                $resultArray = array_merge($resultArray, static::flatArrayRecursive($value));
25
            } else {
26 19
                $resultArray[] = $value;
27
            }
28
        }
29
30 19
        return $resultArray;
31
    }
32
}
33