Completed
Push — master ( b03e32...ac7ae3 )
by Sérgio
05:24
created

ifelse.php ➔ ifelse()   A

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 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 8
c 1
b 0
f 1
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
/**
6
 * @author Sérgio Rafael Siqueira <[email protected]>
7
 *
8
 * @return mixed
9
 */
10
function ifelse()
11
{
12 1
    $args = func_get_args();
13
14
    $ifelse = function ($condition, $onTrue, $onFalse) {
15
        return function ($args) use ($condition, $onTrue, $onFalse) {
16 1
            if (call_user_func($condition, $args)) {
17 1
                return call_user_func($onTrue, $args);
18
            }
19
20 1
            return call_user_func($onFalse, $args);
21 1
        };
22 1
    };
23
24 1
    return call_user_func_array(curry($ifelse), $args);
25
}
26