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

ForkBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A disjoin() 0 7 1
A join() 0 5 1
A buildPrevious() 0 8 2
A build() 0 4 1
1
<?php
2
3
namespace League\Pipeline;
4
5
6
class ForkBuilder implements ForkBuilderInterface
7
{
8
    /**
9
     * @var PipelineBuilder
10
     */
11
    private $parent;
12
13
14
    private $forks = [];
15
16
    private $resolver;
17
18
    /**
19
     * @var BuilderInterface
20
     */
21
    private $currentBuilder;
22
    private $currentTag;
23
24
    public function __construct(callable $resolver, PipelineBuilder $parent)
25
    {
26
        $this->resolver = $resolver;
27
        $this->parent = $parent;
28
    }
29
30
    public function disjoin(string $tag, callable $stage = null)
31
    {
32
        $this->buildPrevious();
33
        $this->currentTag = $tag;
34
        $this->currentBuilder = new DisjointPipelineBuilder($this, $stage);
35
        return $this->currentBuilder;
36
    }
37
38
    public function join()
39
    {
40
        $this->buildPrevious();
41
        return $this->parent;
42
    }
43
44
    private function buildPrevious()
45
    {
46
        if($this->currentTag == null) return;
47
        $this->forks[$this->currentTag] = $this->currentBuilder->build();
48
49
        $this->currentTag = null;
50
        $this->currentBuilder = null;
51
    }
52
53
    public function build()
54
    {
55
        return new Fork($this->resolver, $this->forks);
56
    }
57
}
58