Passed
Push — master ( f8eb54...68901a )
by Kirill
04:07
created

Group::id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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;
11
12
use Railt\Compiler\Iterator\LookaheadIterator;
13
use Railt\Parser\Rule\Concatenation;
14
use Railt\Parser\Rule\Production;
15
16
/**
17
 * Class Group
18
 */
19
class Group
20
{
21
    /**
22
     * @var LookaheadIterator
23
     */
24
    private $iterator;
25
26
    /**
27
     * @var Analyzer
28
     */
29
    private $analyzer;
30
31
    /**
32
     * @var string
33
     */
34
    private $rule;
35
36
    /**
37
     * Group constructor.
38
     * @param LookaheadIterator $iterator
39
     * @param Analyzer $analyzer
40
     * @param string|null $rule
41
     */
42
    public function __construct(LookaheadIterator $iterator, Analyzer $analyzer, string $rule = null)
43
    {
44
        $this->iterator = $iterator;
45
        $this->analyzer = $analyzer;
46
        $this->rule = $rule;
47
    }
48
49
    /**
50
     * @param string|null $rule
51
     * @return int
52
     */
53
    private function id(string $rule = null): int
54
    {
55
        return $this->analyzer->getMapping()->id($rule);
56
    }
57
58
    /**
59
     * @return Production
60
     */
61
    public function reduce(): Production
62
    {
63
        return new Concatenation($this->id($this->rule), [], $this->rule);
64
    }
65
}
66