Passed
Pull Request — master (#274)
by Christoffer
02:38
created

Location   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getStart() 0 3 1
A getEnd() 0 3 1
A __construct() 0 5 1
A hasSource() 0 3 1
A getSource() 0 3 1
A toArray() 0 5 1
A __toString() 0 3 1
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 bool
59
     */
60
    public function hasSource(): bool
61
    {
62
        return null !== $this->source;
63
    }
64
65
    /**
66
     * @return Source|null
67
     */
68
    public function getSource(): ?Source
69
    {
70
        return $this->source;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function toArray(): array
77
    {
78
        return [
79
            'start'  => $this->start,
80
            'end'    => $this->end,
81
        ];
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function __toString(): string
88
    {
89
        return $this->toJSON();
90
    }
91
}
92