Pipeline::invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace PSB\Core\Pipeline;
3
4
5
class Pipeline implements PipelineInterface
6
{
7
    /**
8
     * @var PipelineStepInterface[]
9
     */
10
    private $stepList;
11
12
    /**
13
     * @param PipelineStepInterface[] $stepList
14
     */
15 5
    public function __construct(array $stepList)
16
    {
17 5
        $this->stepList = $stepList;
18 5
    }
19
20
    /**
21
     * @param PipelineStageContextInterface $context
22
     */
23 3
    public function invoke(PipelineStageContextInterface $context)
24
    {
25 3
        $this->invokeNext($context, 0);
26 3
    }
27
28
    /**
29
     * @param PipelineStageContextInterface $context
30
     * @param int                           $currentIndex
31
     */
32 3
    private function invokeNext(PipelineStageContextInterface $context, $currentIndex)
33
    {
34 3
        if ($currentIndex == count($this->stepList)) {
35 3
            return;
36
        }
37
38 2
        $step = $this->stepList[$currentIndex];
39
40 2
        if ($step instanceof StageConnectorInterface) {
41 1
            $step->invoke(
42 1
                $context,
43
                function ($newContext) use ($currentIndex) {
44 1
                    $this->invokeNext($newContext, $currentIndex + 1);
45 1
                }
46
            );
47
        } else {
48 2
            $step->invoke(
49 2
                $context,
50
                function () use ($context, $currentIndex) {
51 2
                    $this->invokeNext($context, $currentIndex + 1);
52 2
                }
53
            );
54
        }
55 2
    }
56
}
57