LazyQuery   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 41
ccs 17
cts 17
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLoadedQuery() 0 7 2
A loadQuery() 0 7 1
A __construct() 0 4 1
A getSource() 0 3 1
A __invoke() 0 3 1
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