flatten.php ➔ flatten()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 8
Bugs 0 Features 4
Metric Value
cc 2
eloc 5
c 8
b 0
f 4
nc 1
nop 1
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
const flatten = '\Sergiors\Functional\flatten';
6
7
/**
8
 * @author Sérgio Rafael Siqueira <[email protected]>
9
 *
10
 * @param array $xs
11
 *
12
 * @return mixed
13
 */
14
function flatten(array $xs)
15
{
16
    return array_reduce($xs, function ($carry, $x) {
17 1
        if (is_array($x)) {
18 1
            return array_merge($carry, flatten($x));
19
        }
20
21 1
        return array_merge($carry, [$x]);
22 1
    }, []);
23
}
24