Completed
Pull Request — master (#128)
by Christoffer
02:13
created

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