Passed
Pull Request — master (#59)
by
unknown
24:02
created

Pipeline::pipe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 3
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Pipeline;
5
6
class Pipeline implements PipelineInterface
7
{
8
    /**
9
     * @var callable[]
10
     */
11
    private $stages;
12
13
    /**
14
     * @var ProcessorInterface
15
     */
16
    private $processor;
17
18 14
    public function __construct(ProcessorInterface $processor = null, callable ...$stages)
19
    {
20 14
        $this->processor = $processor ?? new FingersCrossedProcessor;
21 14
        $this->stages = $stages;
22 14
    }
23
24 8
    public static function init(ProcessorInterface $processor = null, callable ...$stages): PipelineInterface
25
    {
26 8
        return new self($processor, ...$stages);
27 8
    }
28
29 8
    public function pipe(callable $stage): PipelineInterface
30
    {
31
        $pipeline = clone $this;
32 10
        $pipeline->stages[] = $stage;
33
34 10
        return $pipeline;
35
    }
36
37 4
    public function process($payload)
38
    {
39 4
        return $this->processor->process($payload, ...$this->stages);
40
    }
41
42
    public function __invoke($payload)
43
    {
44
        return $this->process($payload);
45
    }
46
}
47