Passed
Pull Request — master (#13)
by
unknown
07:38
created

CList::sum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\churchencoding;
6
7
use Closure;
8
use loophp\combinator\Combinators;
0 ignored issues
show
Bug introduced by
The type loophp\combinator\Combinators was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Class CList.
12
 *
13
 * phpcs:disable Generic.Files.LineLength.TooLong
14
 */
15
final class CList
16
{
17 2
    public static function concat(): Closure
18
    {
19 2
        return static fn (callable $xs): Closure => static fn (callable $ys): Closure => self::foldr()(self::cons())($ys)($xs);
20
    }
21
22 6
    public static function cons(): Closure
23
    {
24 6
        return static fn (callable $a): Closure => static fn (callable $b): Closure => Pair::of()(Boolean::CFalse())(Pair::of()($a)($b));
25
    }
26
27 4
    public static function foldl()
28
    {
29 4
        return static fn (callable $f): Closure => static fn ($a): Closure => static fn (callable $xs) => self::foldr()(
30 4
            static fn (callable $x): Closure => static fn (callable $g): Closure => static fn ($y) => $g($f($y)($x))
31 4
        )(Combinators::I())($xs)($a);
32
    }
33
34 4
    public static function foldr()
35
    {
36 4
        return Combinators::Y()(
37 4
            static fn (callable $r): Closure => static fn (callable $f): Closure => static fn ($a): Closure => static fn (callable $xs) => Boolean::CIf()(self::isNil()($xs))(static fn () => $a)(static fn () => $f(self::head()($xs))($r($f)($a)(self::tail()($xs))))()
38 4
        );
39
    }
40
41 5
    public static function head(): Closure
42
    {
43 5
        return static fn (callable $a): Closure => Pair::first()(Pair::second()($a));
44
    }
45
46 5
    public static function isNil(): Closure
47
    {
48 5
        return Pair::first();
49
    }
50
51 3
    public static function length(): Closure
52
    {
53 3
        return self::foldl()(static fn (callable $a): Closure => static fn (callable $b): Closure => Numeral::succ()($a))(Numeral::zero());
0 ignored issues
show
Unused Code introduced by
The parameter $b is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
        return self::foldl()(static fn (callable $a): Closure => static fn (/** @scrutinizer ignore-unused */ callable $b): Closure => Numeral::succ()($a))(Numeral::zero());

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    }
55
56 6
    public static function nil(): Closure
57
    {
58 6
        return Pair::of()(Boolean::CTrue())(Boolean::CTrue());
59
    }
60
61 2
    public static function range(): Closure
62
    {
63 2
        return static fn (callable $a): Closure => static fn (callable $b): Closure => Numeral::minus()(Numeral::succ()($b))($a)(static fn (callable $c): Closure => CList::cons()(Numeral::minus()($b)(CList::length()($c)))($c))(CList::nil());
64
    }
65
66 2
    public static function repeat(): Closure
67
    {
68 2
        return static fn (callable $a): Closure => static fn (callable $b): Closure => $b(
69 2
            static fn ($c): Closure => CList::cons()($a)($c)
70 2
        )(CList::nil());
71
    }
72
73 1
    public static function sum(): Closure
74
    {
75 1
        return self::foldl()(Numeral::plus())(Numeral::zero());
76
    }
77
78 4
    public static function tail(): Closure
79
    {
80 4
        return static fn (callable $a): Closure => Pair::second()(Pair::second()($a));
81
    }
82
}
83