Passed
Pull Request — master (#22)
by Nico
18:37 queued 03:42
created

BaseToken::createNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license     http://opensource.org/licenses/mit-license.php MIT
5
 * @link        https://github.com/nicoSWD
6
 * @author      Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\Rule\TokenStream\Token;
9
10
use nicoSWD\Rule\Parser\Exception\ParserException;
11
use nicoSWD\Rule\TokenStream\TokenIterator;
12
13
abstract class BaseToken
14
{
15
    abstract public function getType(): TokenType;
16
17
    public function __construct(
18
        private readonly mixed $value,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 18 at column 25
Loading history...
19
        private readonly int $offset = 0,
20
    ) {
21
    }
22 336
23
    public function getValue(): mixed
24 336
    {
25 336
        return $this->value;
26 336
    }
27
28 286
    final public function getOriginalValue(): mixed
29
    {
30 286
        return $this->value;
31
    }
32
33 154
    public function getOffset(): int
34
    {
35 154
        return $this->offset;
36
    }
37
38 90
    /** @throws ParserException */
39
    public function createNode(TokenIterator $tokenStream): self
40 90
    {
41
        return $this;
42
    }
43
44 238
    public function isOfType(TokenType $type): bool
45
    {
46 238
        return $this->getType() === $type;
47
    }
48
49 270
    public function canBeIgnored(): bool
50
    {
51 270
        return
52
            $this->isOfType(TokenType::SPACE) ||
53
            $this->isOfType(TokenType::COMMENT);
54 174
    }
55
}
56