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

AbstractNode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getKind() 0 3 1
A getLocationAsArray() 0 3 2
A __toString() 0 3 1
A getLocation() 0 3 1
A toArray() 0 7 1
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