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

Location::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 Location implements SerializationInterface
9
{
10
    use ArrayToJsonTrait;
11
12
    /**
13
     * @var int
14
     */
15
    protected $start;
16
17
    /**
18
     * @var int
19
     */
20
    protected $end;
21
22
    /**
23
     * @var Source|null
24
     */
25
    protected $source;
26
27
    /**
28
     * Location constructor.
29
     *
30
     * @param int         $start
31
     * @param int         $end
32
     * @param Source|null $source
33
     */
34
    public function __construct(int $start, int $end, ?Source $source = null)
35
    {
36
        $this->start  = $start;
37
        $this->end    = $end;
38
        $this->source = $source;
39
    }
40
41
    /**
42
     * @return int
43
     */
44
    public function getStart(): int
45
    {
46
        return $this->start;
47
    }
48
49
    /**
50
     * @return int
51
     */
52
    public function getEnd(): int
53
    {
54
        return $this->end;
55
    }
56
57
    /**
58
     * @return Source|null
59
     */
60
    public function getSource(): ?Source
61
    {
62
        return $this->source;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function toArray(): array
69
    {
70
        return [
71
            'start' => $this->start,
72
            'end'   => $this->end,
73
        ];
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function __toString(): string
80
    {
81
        return $this->toJSON();
82
    }
83
}
84