LexerPushModeAction   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 72
ccs 0
cts 22
cp 0
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getMode() 0 3 1
A getActionType() 0 3 1
A isPositionDependent() 0 3 1
A hashCode() 0 3 1
A equals() 0 11 3
A execute() 0 3 1
A __construct() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antlr\Antlr4\Runtime\Atn\Actions;
6
7
use Antlr\Antlr4\Runtime\Comparison\Hasher;
8
use Antlr\Antlr4\Runtime\Lexer;
9
10
/**
11
 * Implements the `pushMode` lexer action by calling {@see Lexer::pushMode()}
12
 * with the assigned mode.
13
 *
14
 * @author Sam Harwell
15
 */
16
final class LexerPushModeAction implements LexerAction
17
{
18
    /** @var int */
19
    private $mode;
20
21
    public function __construct(int $mode)
22
    {
23
        $this->mode = $mode;
24
    }
25
26
    /**
27
     * Get the lexer mode this action should transition the lexer to.
28
     *
29
     * @return int The lexer mode for this `pushMode` command.
30
     */
31
    public function getMode() : int
32
    {
33
        return $this->mode;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @return int This method returns {@see LexerActionType::PUSH_MODE}.
40
     */
41
    public function getActionType() : int
42
    {
43
        return LexerActionType::PUSH_MODE;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     *
49
     * @return bool This method returns `false`.
50
     */
51
    public function isPositionDependent() : bool
52
    {
53
        return false;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     *
59
     * This action is implemented by calling {@see Lexer::pushMode()} with the
60
     * value provided by {@see LexerPushModeAction::getMode()}.
61
     */
62
    public function execute(Lexer $lexer) : void
63
    {
64
        $lexer->pushMode($this->mode);
65
    }
66
67
    public function hashCode() : int
68
    {
69
        return Hasher::hash($this->getActionType(), $this->mode);
70
    }
71
72
    public function equals(object $other) : bool
73
    {
74
        if ($this === $other) {
75
            return true;
76
        }
77
78
        if (!$other instanceof self) {
79
            return false;
80
        }
81
82
        return $this->mode === $other->mode;
83
    }
84
85
    public function __toString() : string
86
    {
87
        return \sprintf('pushMode(%d)', $this->mode);
88
    }
89
}
90