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

RepetitionBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 34
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
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\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