Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

TokenTrait::hasToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vanderlee\Comprehend\Parser\Output;
4
5
use Vanderlee\Comprehend\Core\Token;
6
7
/**
8
 *
9
 * @author Martijn
10
 */
11
trait TokenTrait
12
{
13
14
    /**
15
     * Name of the token
16
     *
17
     * @var null
18
     */
19
    private $tokenName = null;
20
21
    /**
22
     * Group to which this token belongs (mostly for standard Library tokens
23
     *
24
     * @var string|null
25
     */
26
    private $tokenGroup = null;
27
28
    /**
29
     * Is this token the deepest node in this tree to report a token on?
30
     *
31
     * @var bool
32
     */
33
    private $tokenIsTerminal = false;
34
35
    /**
36
     * @param string $token
37
     * @param string|null $group
38
     * @param bool $isTerminal
39
     * @return $this
40
     */
41
    public function token($token, $group = null, $isTerminal = false)
42
    {
43
        $this->tokenName       = $token;
0 ignored issues
show
Documentation Bug introduced by
It seems like $token of type string is incompatible with the declared type null of property $tokenName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
        $this->tokenGroup      = $group;
45
        $this->tokenIsTerminal = $isTerminal;
46
47
        return $this;
48
    }
49
50
    /**
51
     * Has a token been set for this Parser?
52
     *
53
     * @return bool
54
     */
55
    public function hasToken()
56
    {
57
        return $this->tokenName !== null;
58
    }
59
60
    private function resolveToken(&$input, $offset, $length, &$children, $class)
61
    {
62
        if ($this->tokenIsTerminal) {
63
            $children = [];
64
        }
65
        return new Token($this->tokenGroup, $this->tokenName, $input, $offset, $length, $children, $class);
66
    }
67
68
}