Token::__construct()   A
last analyzed

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
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
9
namespace Zicht\Tool\Script;
10
11
/**
12
 * Wrapper class for tokens
13
 */
14
final class Token
15
{
16
    /**
17
     * Data token type
18
     */
19
    const DATA = 'data';
20
21
    /**
22
     * Start of expression token type
23
     */
24
    const EXPR_START = 'expr_start';
25
26
    /**
27
     * End of expression token type
28
     */
29
    const EXPR_END = 'expr_end';
30
31
    /**
32
     * Identifier token type
33
     */
34
    const IDENTIFIER = 'identifier';
35
36
    /**
37
     * Whitespace token type
38
     */
39
    const WHITESPACE = 'whitespace';
40
41
    /**
42
     * Number token type
43
     */
44
    const NUMBER = 'number';
45
46
    /**
47
     * String token type
48
     */
49
    const STRING = 'string';
50
51
    /**
52
     * Operator token type
53
     */
54
    const OPERATOR = 'operator';
55
56
    /**
57
     * Value token type
58
     */
59
    const KEYWORD = 'keyword';
60
61
    /**
62
     * @var string
63
     */
64
    public $type;
65
66
    /**
67
     * @var mixed
68
     */
69
    public $value;
70
71
    /**
72
     * Construct the token with the passed type and value
73
     *
74
     * @param string $type
75
     * @param string $value
76
     */
77 23
    public function __construct($type, $value = null)
78
    {
79 23
        $this->type = $type;
80 23
        $this->value = $value;
81 23
    }
82
83
84
    /**
85
     * Checks if the token matches the passed type and/or value
86
     *
87
     * @param mixed $type
88
     * @param mixed $value
89
     * @return bool
90
     */
91 20
    public function match($type, $value = null)
92
    {
93 20
        if ($this->type === $type || (is_array($type) && in_array($this->type, $type))) {
94 20
            if (null === $value || $this->value == $value || (is_array($value) && in_array($this->value, $value))) {
95 20
                return true;
96
            }
97 9
        }
98 14
        return false;
99
    }
100
}