Passed
Push — master ( 04d7e0...bd8f2a )
by Kirill
02:28
created

TokenBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 41
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 10 3
A reduce() 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\Grammar\PP2\Builder;
11
12
use Railt\Compiler\Grammar\PP2\Mapping;
13
use Railt\Parser\Rule\Symbol;
14
use Railt\Parser\Rule\Token;
15
16
/**
17
 * Class TokenBuilder
18
 */
19
class TokenBuilder extends Builder
20
{
21
    /**
22
     * @var bool
23
     */
24
    private $keep;
25
26
    /**
27
     * TokenBuilder constructor.
28
     * @param Mapping $mapper
29
     * @param string $name
30
     * @param bool $keep
31
     */
32
    public function __construct(Mapping $mapper, string $name, bool $keep)
33
    {
34
        $this->keep = $keep;
35
        parent::__construct($mapper, $name);
36
    }
37
38
    /**
39
     * @return int
40
     */
41
    public function getId(): int
42
    {
43
        if ($this->id === null) {
44
            $name = $this->name . '<' . ($this->keep ? '+' : '-') . '>';
45
46
            $this->id = $this->mapper->id($name);
47
        }
48
49
        return $this->id;
50
    }
51
52
    /**
53
     * @return Symbol
54
     */
55
    public function reduce(): Symbol
56
    {
57
        return new Token($this->getId(), $this->name, $this->keep);
58
    }
59
}
60