cond.php ➔ cond()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Prelude;
6
7
const cond = __NAMESPACE__.'\cond';
8
9
use Prelude\Exception\CondClauseException;
10
use function Prelude\head;
11
use function Prelude\tail;
12
use function Prelude\ifElse;
13
14
/**
15
 * @see http://elixir-lang.org/getting-started/case-cond-and-if.html#cond
16
 */
17
function cond(array $pairs): \Closure
18
{
19 2
    if ([] === $pairs) {
20 1
        throw new CondClauseException;
21
    }
22
23 2
    [$if, $then] = head($pairs);
0 ignored issues
show
Bug introduced by
The variable $if does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $then does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
24
25
    $else = function ($x) use ($pairs) {
26 2
        return cond(tail($pairs))($x);
27 2
    };
28
29 2
    return ifElse($if)
30 2
        ($then)
31 2
        ($else);
32
}
33