Completed
Push — master ( d7fcc6...aeb790 )
by Christoffer
02:03
created

AbstractNode::getKind()   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\Node;
4
5
use Digia\GraphQL\Config\ConfigObject;
6
use Digia\GraphQL\Language\Location;
7
use Digia\GraphQL\Language\Visitor\AcceptsVisitorsInterface;
8
use Digia\GraphQL\Language\Visitor\AcceptsVisitorsTrait;
9
use Digia\GraphQL\Util\SerializationInterface;
10
use function Digia\GraphQL\Util\jsonEncode;
11
12
abstract class AbstractNode extends ConfigObject implements SerializationInterface, AcceptsVisitorsInterface
13
{
14
    use AcceptsVisitorsTrait;
15
16
    /**
17
     * @var string
18
     */
19
    protected $kind;
20
21
    /**
22
     * @var Location|null
23
     */
24
    protected $location;
25
26
    /**
27
     * @return string
28
     */
29
    public function getKind(): string
30
    {
31
        return $this->kind;
32
    }
33
34
    /**
35
     * @return Location|null
36
     */
37
    public function getLocation(): ?Location
38
    {
39
        return $this->location;
40
    }
41
42
    /**
43
     * @return array|null
44
     */
45
    public function getLocationAsArray(): ?array
46
    {
47
        return null !== $this->location ? $this->location->toArray() : null;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function toArray(): array
54
    {
55
        // TODO: Remove this method when every node implement its own toArray-method.
56
        return [
57
            'kind' => $this->kind,
58
            'loc'  => $this->getLocationAsArray(),
59
        ];
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function toJSON(): string
66
    {
67
        return jsonEncode($this->toArray());
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function __toString(): string
74
    {
75
        return $this->toJSON();
76
    }
77
}
78