get.php ➔ get()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 5
Bugs 0 Features 4
Metric Value
cc 2
eloc 7
c 5
b 0
f 4
nc 1
nop 0
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
const get = '\Sergiors\Functional\get';
6
7
/**
8
 * Returns the value mapped to key, $notfound value if key not present.
9
 *
10
 * @author Sérgio Rafael Siqueira <[email protected]>
11
 *
12
 * @link https://clojuredocs.org/clojure.core/get
13
 *
14
 * @return mixed
15
 */
16
function get(/* ...$args */)
17
{
18 8
    $args = func_get_args();
19
20
    $get = function (array $xs, $x, $notfound = false) {
21 8
        if (array_key_exists($x, $xs)) {
22 7
            return $xs[$x];
23
        }
24
25 4
        return $notfound;
26 8
    };
27
28 8
    return call_user_func_array(partial($get), $args);
29
}
30