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

Query   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 40
ccs 18
cts 19
cp 0.9474
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSource() 0 3 1
A __invoke() 0 13 1
A getCapabilities() 0 3 1
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