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