Code Duplication    Length = 12-12 lines in 5 locations

src/Zicht/Itertools/reductions.php 5 locations

@@ 16-27 (lines=12) @@
13
 *
14
 * @return \Closure
15
 */
16
function add()
17
{
18
    return function ($a, $b) {
19
        if (!is_numeric($a)) {
20
            throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform addition, not %s', is_object($a) ? get_class($a) : gettype($a)));
21
        }
22
        if (!is_numeric($b)) {
23
            throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform addition, not %s', is_object($b) ? get_class($b) : gettype($b)));
24
        }
25
        return $a + $b;
26
    };
27
}
28
29
/**
30
 * Returns a closure that subtracts one number from another
@@ 34-45 (lines=12) @@
31
 *
32
 * @return \Closure
33
 */
34
function sub()
35
{
36
    return function ($a, $b) {
37
        if (!is_numeric($a)) {
38
            throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform subtraction, not %s', is_object($a) ? get_class($a) : gettype($a)));
39
        }
40
        if (!is_numeric($b)) {
41
            throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform subtraction, not %s', is_object($b) ? get_class($b) : gettype($b)));
42
        }
43
        return $a - $b;
44
    };
45
}
46
47
/**
48
 * Returns a closure that multiplies two numbers
@@ 52-63 (lines=12) @@
49
 *
50
 * @return \Closure
51
 */
52
function mul()
53
{
54
    return function ($a, $b) {
55
        if (!is_numeric($a)) {
56
            throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to perform multiplication, not %s', is_object($a) ? get_class($a) : gettype($a)));
57
        }
58
        if (!is_numeric($b)) {
59
            throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to perform multiplication, not %s', is_object($b) ? get_class($b) : gettype($b)));
60
        }
61
        return $a * $b;
62
    };
63
}
64
65
/**
66
 * Returns a closure that returns the smallest of two numbers
@@ 70-81 (lines=12) @@
67
 *
68
 * @return \Closure
69
 */
70
function min()
71
{
72
    return function ($a, $b) {
73
        if (!is_numeric($a)) {
74
            throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to determine minimum, not %s', is_object($a) ? get_class($a) : gettype($a)));
75
        }
76
        if (!is_numeric($b)) {
77
            throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to determine minimum, not %s', is_object($b) ? get_class($b) : gettype($b)));
78
        }
79
        return $a < $b ? $a : $b;
80
    };
81
}
82
83
/**
84
 * Returns a closure that returns the largest of two numbers
@@ 88-99 (lines=12) @@
85
 *
86
 * @return \Closure
87
 */
88
function max()
89
{
90
    return function ($a, $b) {
91
        if (!is_numeric($a)) {
92
            throw new \InvalidArgumentException(sprintf('Argument $A must be numeric to determine maximum, not %s', is_object($a) ? get_class($a) : gettype($a)));
93
        }
94
        if (!is_numeric($b)) {
95
            throw new \InvalidArgumentException(sprintf('Argument $B must be numeric to determine maximum, not %s', is_object($b) ? get_class($b) : gettype($b)));
96
        }
97
        return $a < $b ? $b : $a;
98
    };
99
}
100
101
/**
102
 * Returns a closure that concatenates two strings using $glue