Token::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bavix\Lexer;
4
5
use Bavix\Iterator\Traits\JsonSerializable;
6
7
/**
8
 * Class Token
9
 *
10
 * @package Bavix\Lexer
11
 *
12
 * @property string $token
13
 * @property string $name
14
 * @property int $type
15
 */
16
class Token implements \JsonSerializable
17
{
18
19
    use JsonSerializable;
20
21
    /**
22
     * @var array
23
     */
24
    protected $data = [];
25
26
    /**
27
     * Token constructor.
28
     *
29
     * @param string $data
30
     * @param string $type
31
     */
32 25
    public function __construct($data, $type)
33
    {
34 25
        $this->data['token'] = $data;
35 25
        $this->data['type'] = $type;
36 25
        $this->data['name'] = Validator::get($type);
37 25
    }
38
39
    /**
40
     * @return string
41
     */
42 4
    public function __toString()
43
    {
44 4
        return (string)$this->data['token'];
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return mixed
51
     */
52 24
    public function __get($name)
53
    {
54 24
        return $this->data[$name];
55
    }
56
57
    /**
58
     * @param string $name
59
     * @param string $value
60
     */
61 1
    public function __set($name, $value)
62
    {
63 1
        if ($name === 'type') {
64
            $this->data['name'] = Validator::get($value);
65
        }
66
67 1
        if ($name === 'name') {
68
            $this->data['type'] = Validator::get($value);
69
        }
70
71 1
        $this->data[$name] = $value;
72 1
    }
73
74
    /**
75
     * @param string $name
76
     *
77
     * @return bool
78
     */
79
    public function __isset($name)
80
    {
81
        return isset($this->data[$name]);
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function __debugInfo()
88
    {
89
        return $this->data;
90
    }
91
92
}
93