compose.php ➔ compose()   B
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 39
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 2
nop 0
dl 0
loc 39
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace DaveRoss\FunctionalProgrammingUtils;
4
5
/**
6
 * Compose a function consisting of a series of functions that each take a single parameter
7
 *
8
 * @return \Closure
9
 */
10
function compose()
11
{
12
13
    static $g;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $g. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
14
    if (! isset($g)) {
15
        /**
16
         * Apply function $f to $b iff $b is not null
17
         *
18
         * @param callable $f
19
         * @param mixed    $b
20
         *
21
         * @return mixed
22
         */
23
        $g = function (callable $f, $b) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
24
            return ( null === $b ) ? null : $f( $b );
25
        };
26
    };
27
28
    $fs = array_reverse(func_get_args());
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
29
30
    /**
31
     * Apply a series of functions to $a
32
     *
33
     * @param mixed $a
34
     *
35
     * @return mixed
36
     */
37
    return function ($a) use ($fs, $g) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
38
39
        $b = $a;
40
        foreach ($fs as $fn) {
41
            $b = $g( $fn, $b );
42
        }
43
44
        return $b;
45
46
    };
47
48
}
49