Completed
Pull Request — master (#40)
by
unknown
23:53 queued 21:51
created

ForkBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 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 2
    public function __construct(callable $resolver, PipelineBuilder $parent)
31
    {
32 2
        $this->resolver = $resolver;
33 2
        $this->parent = $parent;
34 2
    }
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