Passed
Branch master (df2ee3)
by Dawid
07:19 queued 02:10
created

ArrayUtils::flatArrayRecursive()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

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