curry.php ➔ partially_apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DaveRoss\FunctionalProgrammingUtils;
4
5
/**
6
 * Partially apply a function, partially applying the first parameter and returning a function that takes the remaining parameters
7
 *
8
 * @param callable $x
9
 * @param mixed    $y
10
 *
11
 * @return \Closure
12
 */
13
function partially_apply(callable $x, $y)
0 ignored issues
show
Coding Style introduced by
function partially_apply() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $x. 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 $y. 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
{
15
    return function () use ($x, $y) {
16
        return call_user_func_array($x, array_merge(array( $y ), func_get_args()));
17
    };
18
}
19
20
/**
21
 * Partially apply a function, partially applying the last parameter and returning a function that takes the remaining parameters
22
 *
23
 * @param callable $x
24
 * @param mixed    $y
25
 *
26
 * @return \Closure
27
 */
28
function partially_apply_right(callable $x, $y)
0 ignored issues
show
Coding Style introduced by
function partially_apply_right() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $x. 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 $y. 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
    return function () use ($x, $y) {
31
        return call_user_func_array($x, array_merge(func_get_args(), array( $y )));
32
    };
33
}
34
35
/**
36
 * Curry a function, partially applying a parameter and returning a function that takes the next required parameter until all are satisfied
37
 *
38
 * @param callable $x
39
 * @param mixed    $y
40
 *
41
 * @return \Closure
42
 */
43
function curry(callable $x, $y)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $x. 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 $y. 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...
44
{
45
    $params = array( $y );
46
    $required_parameters = ( new \ReflectionFunction($x) )->getNumberOfRequiredParameters();
0 ignored issues
show
Coding Style introduced by
$required_parameters does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
47
48
    if (1 === $required_parameters) {
0 ignored issues
show
Coding Style introduced by
$required_parameters does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
49
        return call_user_func($x, $y);
50
    } else {
51
        return $fn = function ($z = null) use ($x, &$params, $required_parameters, &$fn) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $z. 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 $fn. 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...
52
                $params[] = $z;
53
            if (count($params) === $required_parameters) {
0 ignored issues
show
Coding Style introduced by
$required_parameters does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
54
                return call_user_func_array($x, $params);
55
            } else {
56
                return $fn;
57
            }
58
        };
59
    }
60
}
61