Completed
Pull Request — master (#40)
by
unknown
24:33
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
 * Created by PhpStorm.
4
 * User: juzerali
5
 * Date: 09/01/18
6
 * Time: 7:35 PM
7
 */
8
9
namespace League\Pipeline;
10
11
12
class ForkBuilder implements ForkBuilderInterface
13
{
14
    /**
15
     * @var PipelineBuilder
16
     */
17
    private $parent;
18
19
20
    private $forks = [];
21
22
    private $resolver;
23
24
    /**
25
     * @var BuilderInterface
26
     */
27
    private $currentBuilder;
28
    private $currentTag;
29
30
    public function __construct(callable $resolver, PipelineBuilder $parent)
31
    {
32
        $this->resolver = $resolver;
33
        $this->parent = $parent;
34
    }
35
36
    public function disjoin(string $tag, callable $stage = null)
37
    {
38
        $this->buildPrevious();
39
        $this->currentTag = $tag;
40
        $this->currentBuilder = new DisjointPipelineBuilder($this, $stage);
41
        return $this->currentBuilder;
42
    }
43
44
    public function join()
45
    {
46
        $this->buildPrevious();
47
        return $this->parent;
48
    }
49
50
    private function buildPrevious()
51
    {
52
        if($this->currentTag == null) return;
53
        $this->forks[$this->currentTag] = $this->currentBuilder->build();
54
55
        $this->currentTag = null;
56
        $this->currentBuilder = null;
57
    }
58
59
    public function build()
60
    {
61
        return new Fork($this->resolver, $this->forks);
62
    }
63
}
64