head.php ➔ head()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

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