Completed
Push — master ( e0f246...b9bc84 )
by Sérgio
04:27
created

get.php ➔ get()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 8
c 1
b 0
f 1
nc 1
nop 0
dl 16
loc 16
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
/**
6
 * Returns the value mapped to key, notfound or false if key not present.
7
 *
8
 * @author Sérgio Rafael Siqueira <[email protected]>
9
 *
10
 * @link https://clojuredocs.org/clojure.core/get
11
 *
12
 * @return mixed
13
 */
14 View Code Duplication
function get()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16 1
    $args = func_get_args();
17
18
    $get = function ($map, $key, $notfound = false) {
19 1
        $map = (array) $map;
20
        
21 1
        if (array_key_exists($key, $map)) {
22 1
            return $map[$key];
23
        }
24
25 1
        return $notfound;
26 1
    };
27
28 1
    return call_user_func_array(curry($get), $args);
29
}
30