QueryResult::getSource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Pointer\Query;
6
7
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8
use Remorhaz\JSON\Pointer\Locator\ReferenceInterface;
9
10
final class QueryResult implements QueryResultInterface
11
{
12
13
    private $source;
14
15
    private $selection;
16
17
    private $parent;
18
19
    private $lastReference;
20
21 13
    public function __construct(
22
        string $source,
23
        ?NodeValueInterface $selection = null,
24
        ?NodeValueInterface $parent = null,
25
        ?ReferenceInterface $lastReference = null
26
    ) {
27 13
        $this->source = $source;
28 13
        $this->selection = $selection;
29 13
        $this->parent = $parent;
30 13
        $this->lastReference = $lastReference;
31 13
    }
32
33 1
    public function getSource(): string
34
    {
35 1
        return $this->source;
36
    }
37
38 2
    public function getSelection(): NodeValueInterface
39
    {
40 2
        if (isset($this->selection)) {
41 1
            return $this->selection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->selection could return the type null which is incompatible with the type-hinted return Remorhaz\JSON\Data\Value\NodeValueInterface. Consider adding an additional type-check to rule them out.
Loading history...
42
        }
43
44 1
        throw new Exception\SelectionNotFoundException($this->source);
45
    }
46
47 2
    public function hasSelection(): bool
48
    {
49 2
        return isset($this->selection);
50
    }
51
52 2
    public function getParent(): NodeValueInterface
53
    {
54 2
        if (isset($this->parent)) {
55 1
            return $this->parent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parent could return the type null which is incompatible with the type-hinted return Remorhaz\JSON\Data\Value\NodeValueInterface. Consider adding an additional type-check to rule them out.
Loading history...
56
        }
57
58 1
        throw new Exception\ParentNotFoundException($this->source);
59
    }
60
61 2
    public function hasParent(): bool
62
    {
63 2
        return isset($this->parent);
64
    }
65
66 2
    public function getLastReference(): ReferenceInterface
67
    {
68 2
        if (isset($this->lastReference)) {
69 1
            return $this->lastReference;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->lastReference could return the type null which is incompatible with the type-hinted return Remorhaz\JSON\Pointer\Locator\ReferenceInterface. Consider adding an additional type-check to rule them out.
Loading history...
70
        }
71
72 1
        throw new Exception\LastReferenceNotFoundException($this->source);
73
    }
74
75 2
    public function hasLastReference(): bool
76
    {
77 2
        return isset($this->lastReference);
78
    }
79
}
80