Completed
Push — master ( 5c5634...4e7205 )
by personal
05:16
created

Token   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 8
c 3
b 2
f 0
lcom 1
cbo 0
dl 0
loc 65
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 15 5
A getType() 0 4 1
A getValue() 0 4 1
A asString() 0 3 1
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\Token;
11
12
/**
13
 * Representation of Token
14
 *
15
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
16
 */
17
class Token {
18
    /**
19
     * Type of token
20
     *
21
     * @var integer
22
     */
23
    private $type;
24
25
    /**
26
     * Value of token
27
     *
28
     * @var string
29
     */
30
    private $value;
31
32
    /**
33
     * Constructor
34
     * @param string|array $data
35
     */
36
    public function __construct($data)
37
    {
38
        if(!is_array($data)) {
39
            $this->type = T_STRING;
40
            $this->value = $data;
41
        } else {
42
            $this->type = $data[0];
43
            $this->value = isset($data[1]) ? $data[1] : null;
44
        }
45
46
        // reduce multiple spaces to one
47
        if(T_WHITESPACE  === $this->type && preg_match('/^\s*$/', $this->value)) {
48
            $this->value = ' ';
49
        }
50
    }
51
52
    /**
53
     * Get the type of token
54
     *
55
     * @return integer
56
     */
57
    public function getType()
58
    {
59
        return $this->type;
60
    }
61
62
    /**
63
     * Get value of token
64
     *
65
     * @return string
66
     */
67
    public function getValue()
68
    {
69
        return $this->value;
70
    }
71
72
    /**
73
     * String representation
74
     *
75
     * @return integer
76
     */
77
    public function asString() {
78
        return $this->getValue();
79
    }
80
81
}