Completed
Pull Request — master (#16)
by Siwapun
10:29
created

isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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