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

BaseToken   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 75
ccs 22
cts 28
cp 0.7856
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
getType() 0 1 ?
A __construct() 0 5 1
A getValue() 0 4 1
A getOriginalValue() 0 4 1
A getOffset() 0 4 1
A isOfType() 0 4 1
A createNode() 0 4 1
A isValue() 0 4 1
A isWhitespace() 0 4 1
A isMethod() 0 4 1
A isComma() 0 4 1
A isOperator() 0 4 1
A isLogical() 0 4 1
A isParenthesis() 0 4 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