Total Complexity | 4 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 10 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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) |
|
22 | 14 | } |
|
23 | |||
24 | 8 | public function pipe(callable $stage): PipelineInterface |
|
25 | { |
||
26 | 8 | $pipeline = clone $this; |
|
27 | 8 | $pipeline->stages[] = $stage; |
|
28 | |||
29 | 8 | return $pipeline; |
|
30 | } |
||
31 | |||
32 | 10 | public function process($payload) |
|
33 | { |
||
34 | 10 | return $this->processor->process($payload, ...$this->stages); |
|
35 | } |
||
36 | |||
37 | 4 | public function __invoke($payload) |
|
40 | } |
||
41 | } |
||
42 |