Passed
Push — master ( 19edd7...304f15 )
by Sérgio
02:36
created

Reduce::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Sergiors\Pipeline;
4
5
/**
6
 * @author Sérgio Rafael Siqueira <[email protected]>
7
 */
8
final class Reduce
9
{
10
    /**
11
     * @var \Closure
12
     */
13
    private $fn;
14
15
    /**
16
     * @var mixed
17
     */
18
    private $initial;
19
20
    /**
21
     * @param \Closure $fn
22
     * @param null     $initial
23
     */
24 1
    public function __construct(\Closure $fn, $initial = null)
25
    {
26 1
        $this->fn = $fn;
27 1
        $this->initial = $initial;
28 1
    }
29
30
    /**
31
     * @param mixed $payload
32
     *
33
     * @return mixed
34
     */
35 1
    public function __invoke($payload)
36
    {
37 1
        return array_reduce($payload, $this->fn, $this->initial);
38
    }
39
}
40