Completed
Push — master ( b03e32...44190a )
by Sérgio
03:19
created

pipe.php ➔ Sergiors\Functional\pipe()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2
Metric Value
cc 2
eloc 10
nc 1
nop 0
dl 20
loc 20
ccs 9
cts 9
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
 * Performs left-to-right function composition.
9
 * The leftmost function may have any arity; the remaining functions must be unary.
10
 *
11
 * @return mixed
12
 */
13 View Code Duplication
function pipe()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15 2
    $ls = func_get_args();
16
17
    $pipe = function (array $ls) {
18
        return array_reduce($ls, function ($carry, $fn) {
19 2
            if (is_null($carry)) {
20 2
                return $fn;
21
            }
22
23
            return function () use ($carry, $fn) {
24 2
                $args = func_get_args();
25
26 2
                return $fn(call_user_func_array($carry, $args));
27 2
            };
28 2
        });
29 2
    };
30
31 2
    return call_user_func(curry($pipe), $ls);
32
}
33