Passed
Push — master ( a89473...8b9f9e )
by Edward
14:25
created

MatchFail   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 1
b 0
f 0
dl 0
loc 56
ccs 0
cts 9
cp 0
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
     */
19
    private $offsets;
20
21
    public function __construct(int ...$offsets)
22
    {
23
        $this->offsets = $offsets;
24
    }
25
26
    /**
27
     * @return bool
28
     * @psalm-pure
29
     */
30
    public function shouldRepeat(): bool
31
    {
32
        return false;
33
    }
34
35
    /**
36
     * @return bool
37
     * @psalm-pure
38
     */
39
    public function hasToken(): bool
40
    {
41
        return false;
42
    }
43
44
    /**
45
     * @return TokenInterface
46
     * @psalm-pure
47
     */
48
    public function getToken(): TokenInterface
49
    {
50
        throw new Exception\TokenNotMatchedException($this->offsets);
51
    }
52
53
    /**
54
     * @return bool
55
     * @psalm-pure
56
     */
57
    public function hasLexeme(): bool
58
    {
59
        return true;
60
    }
61
62
    /**
63
     * @return LexemeInterface
64
     * @psalm-pure
65
     */
66
    public function getLexeme(): LexemeInterface
67
    {
68
        return EmptyLexeme::fromOffsets(...$this->offsets);
69
    }
70
}
71