Either.php ➔ either()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 3
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DaveRoss\FunctionalProgrammingUtils;
4
5
/**
6
 * Class Either
7
 * Base class for an Either Monad
8
 * @package DaveRoss\FunctionalProgrammingUtils
9
 */
10
abstract class Either extends Monad
0 ignored issues
show
Coding Style introduced by
Either does not seem to conform to the naming convention (^Abstract|Factory$).

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...
11
{
12
}
13
14
/**
15
 * Helper function to apply one of a pair of function to Either a Left or Right . Returns the value directly rather
16
 * than wrapping it in another Either.
17
 *
18
 * @param callable $f function to apply if $e is a Left
19
 * @param callable $g function to apply if $e is a Right
20
 * @param Either   $e
21
 *
22
 * @return mixed
23
 */
24
function either(callable $f, callable $g, Either $e)
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 $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...
Comprehensibility introduced by
Avoid variables with short names like $e. 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...
25
{
26
27
    switch (get_class($e)) {
28
        case 'DaveRoss\FunctionalProgrammingUtils\Left':
29
            return $f( $e->value() );
30
        case 'DaveRoss\FunctionalProgrammingUtils\Right':
0 ignored issues
show
introduced by
Something seems to be off here. Are you sure you want to declare the constructor as private, and the class as abstract?
Loading history...
31
            return $g( $e->value() );
32
    }
33
34
}