PipeTest::firstParamIsArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Prelude\Tests;
4
5
use function Prelude\pipe;
6
7
class PipeTest extends \PHPUnit\Framework\TestCase
8
{
9
    /**
10
     * @test
11
     */
12 View Code Duplication
    public function shouldRunFunctionHasManyAriry()
0 ignored issues
show
Duplication introduced by
This method 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...
13
    {
14
        $fn = pipe(
15
            function ($x, $y) { return $x * $y; },
16
            function ($x) { return $x / 3; }
17
        );
18
19
        $this->assertEquals($fn(10, 15), 50);
20
    }
21
22
    /**
23
     * @tests
24
     */
25 View Code Duplication
    public function shouldPipedResult()
0 ignored issues
show
Duplication introduced by
This method 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...
26
    {
27
        $fn = pipe(
28
            function ($x) { return "foo($x)"; },
29
            function ($x) { return "bar($x)"; },
30
            function ($x) { return "baz($x)"; }
31
        );
32
        
33
        $this->assertSame($fn('x'), 'baz(bar(foo(x)))');
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function whenRestParamsIsArray()
40
    {
41
        $c = ['foo' => 10];
42
        $p = function (int $x, array $c) {
43
            return $x + $c['foo'];
44
        };
45
46
        $sum = function (int $x) use ($c) {
47
            return $x + $c['foo'];
48
        };
49
50
        $f = pipe($p, $sum, $sum);
51
52
        $this->assertEquals(40, $f(10, $c));
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function firstParamIsArray()
59
    {
60
        $p = pipe(
61
            'array_sum',
62
            function (int $x) {
63
                return $x * 2;
64
            }
65
        );
66
67
        $this->assertEquals(12, $p([1, 2, 3]));
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function shouldSum()
74
    {
75
        $sum = function ($x = null) {
76
            return $x
77
                ? $x + 10
78
                : 10;
79
        };
80
        $f = pipe($sum, $sum, $sum);
81
82
        $this->assertEquals(30, $f());
83
    }
84
}
85