RangeTransition::getSerializationType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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