Passed
Push — master ( 3d52a7...3a32e2 )
by Edward
02:11
created

QueryResult   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 68
ccs 26
cts 26
cp 1
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A hasLastReference() 0 3 1
A __construct() 0 10 1
A getParent() 0 7 2
A hasParent() 0 3 1
A getSelection() 0 7 2
A getLastReference() 0 7 2
A hasSelection() 0 3 1
A getSource() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Pointer\Query;
5
6
use Remorhaz\JSON\Data\Value\NodeValueInterface;
7
use Remorhaz\JSON\Pointer\Locator\ReferenceInterface;
8
9
final class QueryResult implements QueryResultInterface
10
{
11
12
    private $source;
13
14
    private $selection;
15
16
    private $parent;
17
18
    private $lastReference;
19
20 13
    public function __construct(
21
        string $source,
22
        ?NodeValueInterface $selection = null,
23
        ?NodeValueInterface $parent = null,
24
        ?ReferenceInterface $lastReference = null
25
    ) {
26 13
        $this->source = $source;
27 13
        $this->selection = $selection;
28 13
        $this->parent = $parent;
29 13
        $this->lastReference = $lastReference;
30 13
    }
31
32 1
    public function getSource(): string
33
    {
34 1
        return $this->source;
35
    }
36
37 2
    public function getSelection(): NodeValueInterface
38
    {
39 2
        if (isset($this->selection)) {
40 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...
41
        }
42
43 1
        throw new Exception\SelectionNotFoundException($this->source);
44
    }
45
46 2
    public function hasSelection(): bool
47
    {
48 2
        return isset($this->selection);
49
    }
50
51 2
    public function getParent(): NodeValueInterface
52
    {
53 2
        if (isset($this->parent)) {
54 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...
55
        }
56
57 1
        throw new Exception\ParentNotFoundException($this->source);
58
    }
59
60 2
    public function hasParent(): bool
61
    {
62 2
        return isset($this->parent);
63
    }
64
65 2
    public function getLastReference(): ReferenceInterface
66
    {
67 2
        if (isset($this->lastReference)) {
68 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...
69
        }
70
71 1
        throw new Exception\LastReferenceNotFoundException($this->source);
72
    }
73
74 2
    public function hasLastReference(): bool
75
    {
76 2
        return isset($this->lastReference);
77
    }
78
}
79