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

LazyQuery   A

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
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