Symbol::getCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\IO;
6
7
use function array_merge;
8
9
/**
10
 * @psalm-immutable
11
 */
12
final class Symbol implements SymbolInterface, LexemeInterface
13
{
14
15
    /**
16
     * @var int
17
     */
18
    private $offset;
19
20
    /**
21
     * @var int
22
     */
23
    private $code;
24
25
    /**
26
     * @var LexemeInterface
27
     */
28
    private $constituentLexeme;
29
30 9
    public function __construct(int $offset, int $code, LexemeInterface $constituentLexeme)
31
    {
32 9
        $this->offset = $offset;
33 9
        $this->code = $code;
34 9
        $this->constituentLexeme = $constituentLexeme;
35 9
    }
36
37
    /**
38
     * @return int
39
     * @psalm-pure
40
     */
41 1
    public function getOffset(): int
42
    {
43 1
        return $this->offset;
44
    }
45
46
    /**
47
     * @return int
48
     * @psalm-pure
49
     */
50 1
    public function getCode(): int
51
    {
52 1
        return $this->code;
53
    }
54
55
    /**
56
     * @return LexemeInterface
57
     * @psalm-pure
58
     */
59 1
    public function getLexeme(): LexemeInterface
60
    {
61 1
        return $this;
62
    }
63
64
    /**
65
     * @return SymbolInterface[]
66
     * @psalm-return array<int,SymbolInterface>
67
     * @psalm-pure
68
     */
69 1
    public function getSymbols(): array
70
    {
71 1
        return [$this];
72
    }
73
74
    /**
75
     * @return LexemeInterface
76
     * @spalm-pure
77
     */
78 1
    public function getConstituentLexeme(): LexemeInterface
79
    {
80 1
        return $this->constituentLexeme;
81
    }
82
83
    /**
84
     * @return int[]
85
     * @psalm-return array<int,int>
86
     * @psalm-pure
87
     */
88 2
    public function getStartOffsets(): array
89
    {
90 2
        return array_merge([$this->offset], $this->constituentLexeme->getStartOffsets());
91
    }
92
93
    /**
94
     * @return int[]
95
     * @psalm-return array<int,int>
96
     * @psalm-pure
97
     */
98 2
    public function getFinishOffsets(): array
99
    {
100 2
        return array_merge([$this->offset], $this->constituentLexeme->getFinishOffsets());
101
    }
102
}
103