Completed
Push — master ( 22fff6...9c0de7 )
by Kirill
03:23
created

Builder::future()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler\Builder;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Railt\Reflection\Contracts\Definition;
14
use Railt\SDL\Compiler\Factory;
15
use Railt\SDL\Compiler\Pipeline;
16
17
/**
18
 * Class Builder
19
 */
20
abstract class Builder implements BuilderInterface
21
{
22
    /**
23
     * @var Pipeline
24
     */
25
    private $pipeline;
26
27
    /**
28
     * @var Factory
29
     */
30
    private $factory;
31
32
    /**
33
     * Builder constructor.
34
     * @param Pipeline $pipeline
35
     * @param Factory $factory
36
     */
37 1
    public function __construct(Pipeline $pipeline, Factory $factory)
38
    {
39 1
        $this->pipeline = $pipeline;
40 1
        $this->factory = $factory;
41 1
    }
42
43
    /**
44
     * @param \Closure $then
45
     * @return Builder
46
     */
47
    protected function future(\Closure $then): Builder
48
    {
49
        $this->pipeline->push(3, $then);
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param \Closure $then
56
     * @return Builder
57
     */
58
    protected function deferred(\Closure $then): Builder
59
    {
60
        $this->pipeline->push(2, $then);
61
62
        return $this;
63
    }
64
65
    /**
66
     * @param RuleInterface $ast
67
     * @param Definition $parent
68
     * @return Definition
69
     * @throws \Railt\Io\Exception\ExternalFileException
70
     */
71
    protected function dependent(RuleInterface $ast, Definition $parent): Definition
72
    {
73
        return $this->factory->build($ast, $parent);
74
    }
75
}
76