Passed
Push — master ( 3a32e2...77143f )
by Edward
04:21
created

LazyQuery::__invoke()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Parser\ParserInterface;
8
9
final class LazyQuery implements QueryInterface
10
{
11
12
    private $source;
13
14
    private $parser;
15
16
    private $loadedQuery;
17
18 3
    public function __construct(string $source, ParserInterface $parser)
19
    {
20 3
        $this->source = $source;
21 3
        $this->parser = $parser;
22 3
    }
23
24 2
    public function __invoke(NodeValueInterface $rootNode): QueryResultInterface
25
    {
26 2
        return $this->getLoadedQuery()($rootNode);
27
    }
28
29 1
    public function getSource(): string
30
    {
31 1
        return $this->source;
32
    }
33
34 2
    private function getLoadedQuery(): QueryInterface
35
    {
36 2
        if (!isset($this->loadedQuery)) {
37 2
            $this->loadedQuery = $this->loadQuery();
38
        }
39
40 2
        return $this->loadedQuery;
41
    }
42
43 2
    private function loadQuery(): QueryInterface
44
    {
45 2
        return new Query(
46 2
            $this->source,
47
            $this
48 2
                ->parser
49 2
                ->buildLocator($this->source),
50
        );
51
    }
52
}
53