RangeTransition   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 49
ccs 0
cts 23
cp 0
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A label() 0 3 1
A getSerializationType() 0 3 1
A equals() 0 10 5
A matches() 0 3 2
A __toString() 0 6 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antlr\Antlr4\Runtime\Atn\Transitions;
6
7
use Antlr\Antlr4\Runtime\Atn\States\ATNState;
8
use Antlr\Antlr4\Runtime\IntervalSet;
9
use Antlr\Antlr4\Runtime\Utils\StringUtils;
10
11
final class RangeTransition extends Transition
12
{
13
    /** @var int */
14
    public $from;
15
16
    /** @var int */
17
    public $to;
18
19
    public function __construct(ATNState $target, int $from, int $to)
20
    {
21
        parent::__construct($target);
22
23
        $this->from = $from;
24
        $this->to = $to;
25
    }
26
27
    public function label() : ?IntervalSet
28
    {
29
        return IntervalSet::fromRange($this->from, $this->to);
30
    }
31
32
    public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool
33
    {
34
        return $symbol >= $this->from && $symbol <= $this->to;
35
    }
36
37
    public function getSerializationType() : int
38
    {
39
        return self::RANGE;
40
    }
41
42
    public function equals(object $other) : bool
43
    {
44
        if ($this === $other) {
45
            return true;
46
        }
47
48
        return $other instanceof self
49
            && $this->from === $other->from
50
            && $this->to === $other->to
51
            && $this->target->equals($other->target);
52
    }
53
54
    public function __toString() : string
55
    {
56
        return \sprintf(
57
            '\'%s\'..\'%s\'',
58
            StringUtils::char($this->from),
59
            StringUtils::char($this->to)
60
        );
61
    }
62
}
63