Passed
Pull Request — master (#128)
by Christoffer
02:40
created

Token::toJSON()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Digia\GraphQL\Language;
4
5
use Digia\GraphQL\Util\ArrayToJsonTrait;
6
use Digia\GraphQL\Util\SerializationInterface;
7
8
class Token implements SerializationInterface
9
{
10
    use ArrayToJsonTrait;
11
12
    /**
13
     * @var string
14
     */
15
    private $kind;
16
17
    /**
18
     * @var int
19
     */
20
    private $start;
21
22
    /**
23
     * @var int
24
     */
25
    private $end;
26
27
    /**
28
     * @var int
29
     */
30
    private $line;
31
32
    /**
33
     * @var int
34
     */
35
    private $column;
36
37
    /**
38
     * @var ?Token
39
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ?Token at position 0 could not be parsed: Unknown type name '?Token' at position 0 in ?Token.
Loading history...
40
    private $prev;
41
42
    /**
43
     * @var ?Token
44
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ?Token at position 0 could not be parsed: Unknown type name '?Token' at position 0 in ?Token.
Loading history...
45
    private $next;
46
47
    /**
48
     * @var ?string
49
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ?string at position 0 could not be parsed: Unknown type name '?string' at position 0 in ?string.
Loading history...
50
    private $value;
51
52
    /**
53
     * Token constructor.
54
     *
55
     * @param string     $kind
56
     * @param int        $start
57
     * @param int        $end
58
     * @param int        $line
59
     * @param int        $column
60
     * @param Token|null $prev
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
61
     * @param null       $value
62
     */
63
    public function __construct(
64
        string $kind,
65
        int $start = 0,
66
        int $end = 0,
67
        int $line = 0,
68
        int $column = 0,
69
        ?Token $prev = null,
70
        $value = null
71
    ) {
72
        $this->kind   = $kind;
73
        $this->start  = $start;
74
        $this->end    = $end;
75
        $this->line   = $line;
76
        $this->column = $column;
77
        $this->prev   = $prev;
78
        $this->value  = $value;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getKind(): string
85
    {
86
        return $this->kind;
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function getStart(): int
93
    {
94
        return $this->start;
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getEnd(): int
101
    {
102
        return $this->end;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getLine(): int
109
    {
110
        return $this->line;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getColumn(): int
117
    {
118
        return $this->column;
119
    }
120
121
    /**
122
     * @return Token|null
123
     */
124
    public function getPrev(): ?Token
125
    {
126
        return $this->prev;
127
    }
128
129
    /**
130
     * @return Token|null
131
     */
132
    public function getNext(): ?Token
133
    {
134
        return $this->next;
135
    }
136
137
    /**
138
     * @param Token $next
139
     * @return $this
140
     */
141
    public function setNext(Token $next)
142
    {
143
        $this->next = $next;
144
        return $this;
145
    }
146
147
    /**
148
     * @return mixed
149
     */
150
    public function getValue()
151
    {
152
        return $this->value;
153
    }
154
155
    /**
156
     * @inheritdoc
157
     */
158
    public function toArray(): array
159
    {
160
        return [
161
            'kind'   => $this->kind,
162
            'value'  => $this->value,
163
            'line'   => $this->line,
164
            'column' => $this->column,
165
        ];
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    public function __toString(): string
172
    {
173
        return $this->value !== null
174
            ? sprintf('%s "%s"', $this->kind, $this->value)
175
            : $this->kind;
176
    }
177
}
178