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

RepetitionBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 4
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\Builder;
11
12
use Railt\Compiler\Grammar\PP2\Mapping;
13
use Railt\Parser\Rule\Concatenation;
14
use Railt\Parser\Rule\Production;
15
use Railt\Parser\Rule\Repetition;
16
use Railt\Parser\Rule\Symbol;
17
18
/**
19
 * Class RepetitionBuilder
20
 */
21
class RepetitionBuilder extends Builder
22
{
23
    /**
24
     * @var int
25
     */
26
    private $min;
27
28
    /**
29
     * @var int
30
     */
31
    private $max;
32
33
    /**
34
     * RepetitionBuilder constructor.
35
     * @param Mapping $mapping
36
     * @param int $min
37
     * @param int $max
38
     * @param null|string $name
39
     */
40
    public function __construct(Mapping $mapping, int $min, int $max, ?string $name = null)
41
    {
42
        parent::__construct($mapping, $name);
43
        $this->min = $min;
44
        $this->max = $max;
45
    }
46
47
    /**
48
     * @return Symbol|Production|Concatenation
49
     */
50
    public function reduce(): Symbol
51
    {
52
        return new Repetition($this->getId(), $this->min, $this->max, $this->children, $this->name);
53
    }
54
}
55