Completed
Push — master ( 14d264...b8b70e )
by Portey
05:01
created

Token::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0582

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 18
ccs 11
cts 13
cp 0.8462
rs 9.2
cc 4
eloc 9
nc 8
nop 2
crap 4.0582
1
<?php
2
/**
3
 * Date: 23.11.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Parser;
9
10
class Token
11
{
12
    // Special
13
    const TYPE_END        = 'end';
14
    const TYPE_IDENTIFIER = 'identifier';
15
    const TYPE_NUMBER     = 'number';
16
    const TYPE_STRING     = 'string';
17
    const TYPE_ON         = 'on';
18
19
    const TYPE_QUERY    = 'query';
20
    const TYPE_MUTATION = 'mutation';
21
    const TYPE_FRAGMENT = 'fragment';
22
23
24
    // Punctuators
25
    const TYPE_LT            = '<';
26
    const TYPE_GT            = '>';
27
    const TYPE_LBRACE        = '{';
28
    const TYPE_RBRACE        = '}';
29
    const TYPE_LPAREN        = '(';
30
    const TYPE_RPAREN        = ')';
31
    const TYPE_LSQUARE_BRACE = '[';
32
    const TYPE_RSQUARE_BRACE = ']';
33
    const TYPE_COLON         = ':';
34
    const TYPE_COMMA         = ',';
35
    const TYPE_AMP           = '&';
36
    const TYPE_POINT         = '.';
37
38
    // Keywords
39
    const TYPE_NULL  = 'null';
40
    const TYPE_TRUE  = 'true';
41
    const TYPE_FALSE = 'false';
42
    /** @deprecated */
43
    const TYPE_AS                 = 'as';
44
    const TYPE_FRAGMENT_REFERENCE = '...';
45
46
    private $data;
47
    private $type;
48
49 9
    public function __construct($type, $data = null)
50
    {
51 9
        $this->type = $type;
52 9
        $this->data = $data;
53
54 9
        if ($this->getType() == self::TYPE_TRUE) {
55 2
            $this->data = true;
56 2
        }
57
58 9
        if ($this->getType() == self::TYPE_FALSE) {
59
            $this->data = false;
60
        }
61
62 9
        if ($this->getType() == self::TYPE_NULL) {
63 1
            $this->data = null;
64 1
        }
65
66 9
    }
67
68
    public function toString()
69
    {
70
        return "<" . $this->getData() . ", " . $this->getType() . ">";
71
    }
72
73 8
    public function getData()
74
    {
75 8
        return $this->data;
76
    }
77
78 9
    public function getType()
79
    {
80 9
        return $this->type;
81
    }
82
}