Completed
Push — master ( 88ff28...2dc58f )
by Kirill
06:03
created

Builder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 79
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A jump() 0 6 1
A rename() 0 6 1
A getName() 0 4 1
A getId() 0 4 1
build() 0 1 ?
A __toString() 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\Compiler\Reader\Resolver\Builder;
11
12
use Railt\Parser\Rule\Symbol;
13
14
/**
15
 * Class Builder
16
 */
17
abstract class Builder
18
{
19
    /**
20
     * @var null|string
21
     */
22
    protected $name;
23
24
    /**
25
     * @var int
26
     */
27
    protected $id;
28
29
    /**
30
     * @var array|int[]
31
     */
32
    protected $children = [];
33
34
    /**
35
     * Builder constructor.
36
     * @param int $id
37
     * @param null|string $name
38
     */
39
    public function __construct(int $id, string $name = null)
40
    {
41
        $this->name = $name;
42
        $this->id = $id;
43
    }
44
45
    /**
46
     * @param int $rule
47
     * @return Builder
48
     */
49
    public function jump(int $rule): Builder
50
    {
51
        $this->children[] = $rule;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param null|string $name
58
     * @return Builder
59
     */
60
    public function rename(?string $name): Builder
61
    {
62
        $this->name = $name;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return null|string
69
     */
70
    public function getName(): ?string
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * @return int
77
     */
78
    public function getId(): int
79
    {
80
        return $this->id;
81
    }
82
83
    /**
84
     * @return Symbol
85
     */
86
    abstract public function build(): Symbol;
87
88
    /**
89
     * @return string
90
     */
91
    public function __toString(): string
92
    {
93
        return \class_basename($this);
94
    }
95
}
96