MatchFail   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hasLexeme() 0 3 1
A hasToken() 0 3 1
A getLexeme() 0 3 1
A getToken() 0 3 1
A shouldRepeat() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\Lexer\Runtime\Token;
6
7
use Remorhaz\Lexer\Runtime\IO\EmptyLexeme;
8
use Remorhaz\Lexer\Runtime\IO\LexemeInterface;
9
10
/**
11
 * @psalm-immutable
12
 */
13
final class MatchFail implements MatchResultInterface
14
{
15
16
    /**
17
     * @var int[]
18
     * @psalm-var array<int,int>
19
     */
20
    private $offsets;
21
22 10
    public function __construct(int ...$offsets)
23
    {
24 10
        $this->offsets = $offsets;
25 10
    }
26
27
    /**
28
     * @return bool
29
     * @psalm-pure
30
     */
31 1
    public function shouldRepeat(): bool
32
    {
33 1
        return false;
34
    }
35
36
    /**
37
     * @return bool
38
     * @psalm-pure
39
     */
40 1
    public function hasToken(): bool
41
    {
42 1
        return false;
43
    }
44
45
    /**
46
     * @return TokenInterface
47
     * @psalm-pure
48
     */
49 1
    public function getToken(): TokenInterface
50
    {
51 1
        throw new Exception\TokenNotMatchedException($this->offsets);
52
    }
53
54
    /**
55
     * @return bool
56
     * @psalm-pure
57
     */
58 1
    public function hasLexeme(): bool
59
    {
60 1
        return true;
61
    }
62
63
    /**
64
     * @return LexemeInterface
65
     * @psalm-pure
66
     */
67 6
    public function getLexeme(): LexemeInterface
68
    {
69 6
        return EmptyLexeme::fromOffsets(...$this->offsets);
70
    }
71
}
72