EmptyLexeme   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 77
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSymbols() 0 3 1
A getFinishOffsets() 0 3 1
A fromOffsets() 0 5 2
A getConstituentLexeme() 0 3 1
A getStartOffsets() 0 3 1
A __construct() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\IO;
6
7
use function array_merge;
8
use function array_shift;
9
10
/**
11
 * @psalm-immutable
12
 */
13
final class EmptyLexeme implements LexemeInterface
14
{
15
16
    /**
17
     * @var int
18
     */
19
    private $offset;
20
21
    /**
22
     * @var LexemeInterface
23
     */
24
    private $constituentLexeme;
25
26
    /**
27
     * @param int ...$offsets
28
     * @return LexemeInterface
29
     * @psalm-pure
30
     */
31 6
    public static function fromOffsets(int ...$offsets): LexemeInterface
32
    {
33 6
        return empty($offsets)
34 6
            ? new NullLexeme()
35 6
            : new self(array_shift($offsets), self::fromOffsets(...$offsets));
36
    }
37
38 7
    public function __construct(int $offset, LexemeInterface $constituentLexeme)
39
    {
40 7
        if (!empty($constituentLexeme->getSymbols())) {
41 1
            throw new Exception\NonEmptyLexemeException($constituentLexeme);
42
        }
43 6
        $this->constituentLexeme = $constituentLexeme;
44 6
        $this->offset = $offset;
45 6
    }
46
47
    /**
48
     * {@inheritDoc}
49
     *
50
     * @return SymbolInterface[]
51
     * @psalm-return array<int, SymbolInterface>
52
     * @psalm-pure
53
     */
54 3
    public function getSymbols(): array
55
    {
56 3
        return [];
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     *
62
     * @return int[]
63
     * @psalm-return array<int, int>
64
     */
65 2
    public function getStartOffsets(): array
66
    {
67 2
        return array_merge([$this->offset], $this->constituentLexeme->getStartOffsets());
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     *
73
     * @return int[]
74
     * @psalm-return array<int, int>
75
     */
76 2
    public function getFinishOffsets(): array
77
    {
78 2
        return array_merge([$this->offset], $this->constituentLexeme->getFinishOffsets());
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     *
84
     * @return LexemeInterface
85
     * @psalm-pure
86
     */
87 1
    public function getConstituentLexeme(): LexemeInterface
88
    {
89 1
        return $this->constituentLexeme;
90
    }
91
}
92