Completed
Push — master ( 0acfd1...8c96cb )
by Edward
08:27
created

Query::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Query;
5
6
use Remorhaz\JSON\Path\Value\NodeValueListBuilder;
7
use function call_user_func;
8
use Remorhaz\JSON\Data\Value\NodeValueInterface;
9
use Remorhaz\JSON\Path\Runtime\EvaluatorInterface;
10
use Remorhaz\JSON\Path\Value\ValueListInterface;
11
use Remorhaz\JSON\Path\Runtime\RuntimeInterface;
12
13
final class Query implements QueryInterface
14
{
15
16
    private $source;
17
18
    private $callback;
19
20
    private $properties;
21
22 4
    public function __construct(string $source, callable $callback, CapabilitiesInterface $properties)
23
    {
24 4
        $this->source = $source;
25 4
        $this->callback = $callback;
26 4
        $this->properties = $properties;
27 4
    }
28
29 2
    public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime): ValueListInterface
30
    {
31 2
        $input = (new NodeValueListBuilder)
32 2
            ->addValue($rootNode, 0)
33 2
            ->build();
34
35
        return call_user_func(
36 2
            $this->callback,
37
            $input,
38 2
            $runtime->getValueListFetcher(),
39 2
            $runtime->getEvaluator(),
40 2
            $runtime->getLiteralFactory(),
41 2
            $runtime->getMatcherFactory(),
42
        );
43
    }
44
45 1
    public function getCapabilities(): CapabilitiesInterface
46
    {
47 1
        return $this->properties;
48
    }
49
50 1
    public function getSource(): string
51
    {
52 1
        return $this->source;
53
    }
54
}
55