Test Failed
Push — master ( 08b170...e6bc2a )
by Kirill
02:02
created

Builder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 4
dl 0
loc 78
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A async() 0 4 1
A bind() 0 6 1
A getName() 0 4 1
A findName() 0 4 1
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\Builder;
11
12
use Railt\Io\Readable;
13
use Railt\Parser\Ast\RuleInterface;
14
use Railt\Reflection\AbstractDefinition;
15
use Railt\Reflection\Contracts\Definition;
16
use Railt\Reflection\Contracts\Document;
17
use Railt\SDL\Compiler\Process;
18
19
/**
20
 * Class Builder
21
 */
22
abstract class Builder implements BuilderInterface
23
{
24
    /**
25
     * @var Readable
26
     */
27
    protected $file;
28
29
    /**
30
     * @var Definition
31
     */
32
    protected $definition;
33
34
    /**
35
     * @var Document
36
     */
37
    protected $document;
38
39
    /**
40
     * @var RuleInterface
41
     */
42
    protected $ast;
43
44
    /**
45
     * @var Process
46
     */
47
    private $process;
48
49
    /**
50
     * Builder constructor.
51
     * @param Context $ctx
52
     * @param RuleInterface $ast
53
     * @param Process $process
54
     */
55
    public function __construct(Context $ctx, RuleInterface $ast, Process $process)
56
    {
57
        $this->ast = $ast;
58
        $this->process = $process;
59
        $this->file = $ctx->getFile();
60
        $this->definition = $ctx->getDefinition();
61
        $this->document = $this->definition->getDocument();
62
    }
63
64
    /**
65
     * @param \Closure $then
66
     */
67
    public function async(\Closure $then): void
68
    {
69
        $this->process->async($then);
70
    }
71
72
    /**
73
     * @param Definition|AbstractDefinition $definition
74
     * @return Definition
75
     */
76
    protected function bind(Definition $definition): Definition
77
    {
78
        $definition->withOffset($this->ast->getOffset());
79
80
        return $definition;
81
    }
82
83
    /**
84
     * @return string
85
     * @throws \Railt\SDL\Exception\SyntaxException
86
     */
87
    protected function getName(): string
88
    {
89
        return Utils::getName($this->file, $this->ast);
90
    }
91
92
    /**
93
     * @return string|null
94
     */
95
    protected function findName(): ?string
96
    {
97
        return Utils::findName($this->ast);
98
    }
99
}
100