Completed
Pull Request — master (#40)
by
unknown
21:56
created

PipelineBuilder::buildLast()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
ccs 0
cts 0
cp 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace League\Pipeline;
4
5
use Illuminate\Database\Schema\Builder;
6
7
class PipelineBuilder implements PipelineBuilderInterface
8
{
9
    /**
10
     * @var callable[]
11
     */
12
    protected $stages = [];
13
14
    /**
15
     * @var ProcessorInterface
16
     */
17
    private $processr;
18
19 4
    /**
20
     * @var BuilderInterface
21 4
     */
22
    private $last;
23 4
24
    /**
25
     * Add an stage.
26
     *
27
     * @param callable $stage
28
     *
29
     * @return $this
30
     */
31
    public function pipe(callable $stage)
32
    {
33 4
        $this->buildLast();
34
        $this->stages[] = $stage;
35 4
36
        return $this;
37
    }
38
39
    public function fork(callable $resolver)
40
    {
41
        $this->buildLast();
42
        $this->last = new ForkBuilder($resolver, $this);
43
        return $this->last;
44
    }
45
46
    public function processor(ProcessorInterface $processor)
47
    {
48
        $this->processr = $processor;
49
    }
50
51
    private function buildLast()
52
    {
53
        if($this->last == null) return;
54
        $this->stages[] = $this->last->build();
55
        $this->last = null;
56
    }
57
58
    /**
59
     * Build a new Pipeline object
60
     *
61
     * @return Pipeline
62
     */
63
    public function build()
64
    {
65
        $this->buildLast();
66
        return new Pipeline($this->stages, $this->processr);
67
    }
68
}
69