ifelse.php ➔ ifelse()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 3
Metric Value
cc 2
eloc 8
c 3
b 0
f 3
nc 1
nop 0
dl 0
loc 16
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
const ifelse = '\Sergiors\Functional\ifelse';
6
7
/**
8
 * @author Sérgio Rafael Siqueira <[email protected]>
9
 *
10
 * @return mixed
11
 */
12
function ifelse(/* ...$args */)
13
{
14 1
    $args = func_get_args();
15
16
    $ifelse = function (callable $condition, callable $ontrue, callable $onfalse) {
17
        return function ($x) use ($condition, $ontrue, $onfalse) {
18 1
            if ($condition($x)) {
19 1
                return $ontrue($x);
20
            }
21
22 1
            return $onfalse($x);
23 1
        };
24 1
    };
25
26 1
    return call_user_func_array(partial($ifelse), $args);
27
}
28