Completed
Push — master ( cd8458...170448 )
by
unknown
36s
created

sort.php ➔ sort()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 11
c 2
b 0
f 1
nc 2
nop 1
dl 0
loc 19
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
const sort = '\Sergiors\Functional\sort';
6
7
/**
8
 * @author Sérgio Rafael Siqueira <[email protected]>
9
 *
10
 * @param array $xss
11
 *
12
 * @return array
13
 */
14
function sort(array $xss)
15
{
16 2
    $xss = array_values($xss);
17
18 2
    if (!has(1, $xss)) {
19 2
        return $xss;
20
    }
21
22 2
    $pivot = head($xss);
23 2
    $xs = tail($xss);
24
    $left = array_filter($xs, function ($x) use ($pivot) {
25 2
        return $x < $pivot;
26 2
    });
27
    $right = array_filter($xs, function ($x) use ($pivot) {
28 2
        return $x > $pivot;
29 2
    });
30
31 2
    return array_merge(sort($left), [$pivot], sort($right));
32
}
33