ifElse()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 2
rs 9.7998
c 0
b 0
f 0
1
<?php
2
namespace Aerophant\Ramda;
3
4
/**
5
 * @param bool $firstValue
6
 * @param bool $secondValue
7
 * @return bool|\Closure
8
 */
9
function andLogically()
10
{
11
  $and = function (bool $firstValue, bool $secondValue) {
12 2
    return $firstValue && $secondValue;
13 2
  };
14 2
  $arguments = func_get_args();
15 2
  $curried = curryN($and, 2);
16 2
  return call_user_func_array($curried, $arguments);
17
}
18
19
function defaultTo()
20
{
21
  $defaultTo = function ($defaultValue, $value) {
22 2
    return $value ? $value : $defaultValue;
23 2
  };
24 2
  $arguments = func_get_args();
25 2
  $curried = curryN($defaultTo, 2);
26 2
  return call_user_func_array($curried, $arguments);
27
}
28
29
/**
30
 * (*… → Boolean) → (*… → *) → (*… → *) → (*… → *)
31
 * @param callable $condition
32
 * @param callable $onTrue
33
 * @param callable $onFalse
34
 * @return \Closure
35
 */
36
function ifElse()
37
{
38
  $ifElse = function (callable $condition, callable $onTrue, callable $onFalse) {
39
    return function () use ($condition, $onTrue, $onFalse) {
40 2
      $arguments = func_get_args();
41 2
      if (call_user_func_array($condition, $arguments)) {
42 1
        return call_user_func_array($onTrue, $arguments);
43
      }
44 1
      return call_user_func_array($onFalse, $arguments);
45 2
    };
46 2
  };
47 2
  $arguments = func_get_args();
48 2
  $curried = curryN($ifElse, 3);
49 2
  return call_user_func_array($curried, $arguments);
50
}
51
52
/**
53
 * @param mixed $data
54
 * @return bool|\Closure
55
 */
56
function isEmpty()
57
{
58
  $isEmpty = function ($value) {
59 4
    return empty($value);
60 4
  };
61 4
  $arguments = func_get_args();
62 4
  $curried = curryN($isEmpty, 1);
63 4
  return call_user_func_array($curried, $arguments);
64
}
65
66
/**
67
 * @param mixed $value
68
 * @return bool|\Closure
69
 */
70
function not()
71
{
72
  $not = function ($value) {
73 7
    return !$value;
74 7
  };
75 7
  $arguments = func_get_args();
76 7
  $curried = curryN($not, 1);
77 7
  return call_user_func_array($curried, $arguments);
78
}
79
80
/**
81
 * @param bool $firstValue
82
 * @param bool $secondValue
83
 * @return bool|\Closure
84
 */
85
function orLogically()
86
{
87
  $and = function (bool $firstValue, bool $secondValue) {
88 2
    return $firstValue || $secondValue;
89 2
  };
90 2
  $arguments = func_get_args();
91 2
  $curried = curryN($and, 2);
92 2
  return call_user_func_array($curried, $arguments);
93
}
94