Passed
Push — master ( 78e027...fa2487 )
by Edward
02:26
created

LazyQuery::getProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Query;
5
6
use Remorhaz\JSON\Data\Value\NodeValueInterface;
7
use Remorhaz\JSON\Path\Value\ValueListInterface;
8
use Remorhaz\JSON\Path\Parser\ParserInterface;
9
use Remorhaz\JSON\Path\Runtime\RuntimeInterface;
10
11
final class LazyQuery implements QueryInterface
12
{
13
14
    private $loadedQuery;
15
16
    private $path;
17
18
    private $parser;
19
20
    private $astTranslator;
21
22
    public function __construct(string $path, ParserInterface $parser, QueryAstTranslatorInterface $astTranslator)
23
    {
24
        $this->path = $path;
25
        $this->parser = $parser;
26
        $this->astTranslator = $astTranslator;
27
    }
28
29
    public function __invoke(RuntimeInterface $runtime, NodeValueInterface $rootNode): ValueListInterface
30
    {
31
        return $this->getLoadedQuery()($runtime, $rootNode);
32
    }
33
34
    /**
35
     * @return bool
36
     * @deprecated
37
     */
38
    public function isDefinite(): bool
39
    {
40
        return $this
41
            ->getProperties()
42
            ->isDefinite();
43
    }
44
45
    public function getProperties(): QueryPropertiesInterface
46
    {
47
        return $this
48
            ->getLoadedQuery()
49
            ->getProperties();
50
    }
51
52
    private function getLoadedQuery(): QueryInterface
53
    {
54
        if (!isset($this->loadedQuery)) {
55
            $this->loadedQuery = $this->loadQuery();
56
        }
57
58
        return $this->loadedQuery;
59
    }
60
61
    private function loadQuery(): QueryInterface
62
    {
63
        $queryAst = $this
64
            ->parser
65
            ->buildQueryAst($this->path);
66
67
        return $this
68
            ->astTranslator
69
            ->buildQuery($queryAst);
70
    }
71
}
72