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

PipelineBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 62
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3
rs 10
ccs 5
cts 5
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A pipe() 0 7 1
A fork() 0 6 1
A processor() 0 4 1
A buildLast() 0 6 2
A build() 0 5 1
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