Completed
Push — master ( ab70d1...7a1ec5 )
by Nico
01:25
created

BaseToken::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 * @link        https://github.com/nicoSWD
8
 * @author      Nicolas Oelgart <[email protected]>
9
 */
10
namespace nicoSWD\Rule\TokenStream\Token;
11
12
use nicoSWD\Rule\TokenStream\TokenStream;
13
14
abstract class BaseToken
15
{
16
    /** @var mixed */
17
    private $value;
18
    /** @var int */
19
    private $offset = 0;
20
21
    abstract public function getType(): int;
22
23 228
    public function __construct($value, int $offset = 0)
24
    {
25 228
        $this->value = $value;
26 228
        $this->offset = $offset;
27 228
    }
28
29 212
    public function getValue()
30
    {
31 212
        return $this->value;
32
    }
33
34 94
    final public function getOriginalValue()
35
    {
36 94
        return $this->value;
37
    }
38
39 144
    public function getOffset(): int
40
    {
41 144
        return $this->offset;
42
    }
43
44 208
    public function createNode(TokenStream $tokenStream): self
45
    {
46 208
        return $this;
47
    }
48
49 190
    public function isOfType(int $type): bool
50
    {
51 190
        return ($this->getType() | $type) === $type;
52
    }
53
54 144
    public function isValue(): bool
55
    {
56 144
        return $this->isOfType(TokenType::VALUE | TokenType::INT_VALUE);
57
    }
58
59 186
    public function isWhitespace(): bool
60
    {
61 186
        return $this->isOfType(TokenType::SPACE | TokenType::COMMENT);
62
    }
63
64 186
    public function isMethod(): bool
65
    {
66 186
        return $this->isOfType(TokenType::METHOD);
67
    }
68
69 144
    public function isComma(): bool
70
    {
71 144
        return $this->isOfType(TokenType::COMMA);
72
    }
73
74
    public function isOperator(): bool
75
    {
76
        return $this->isOfType(TokenType::OPERATOR);
77
    }
78
79
    public function isLogical(): bool
80
    {
81
        return $this->isOfType(TokenType::LOGICAL);
82
    }
83
84
    public function isParenthesis(): bool
85
    {
86
        return $this->isOfType(TokenType::PARENTHESIS);
87
    }
88
}
89