Query   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 50
ccs 24
cts 24
cp 1
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSource() 0 3 1
A __invoke() 0 23 2
A getCapabilities() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Query;
6
7
use Remorhaz\JSON\Data\Value\NodeValueInterface;
8
use Remorhaz\JSON\Path\Value\NodeValueListBuilder;
9
use Remorhaz\JSON\Path\Value\ValueListInterface;
10
use Remorhaz\JSON\Path\Runtime\RuntimeInterface;
11
use Throwable;
12
13
use function call_user_func;
14
15
final class Query implements QueryInterface
16
{
17
18
    private $source;
19
20
    private $callbackBuilder;
21
22 5
    public function __construct(string $source, CallbackBuilderInterface $callbackBuilder)
23
    {
24 5
        $this->source = $source;
25 5
        $this->callbackBuilder = $callbackBuilder;
26 5
    }
27
28 3
    public function __invoke(NodeValueInterface $rootNode, RuntimeInterface $runtime): ValueListInterface
29
    {
30
        try {
31
            $callback = $this
32 3
                ->callbackBuilder
33 3
                ->getCallback();
34
35
            $args = [
36 3
                (new NodeValueListBuilder())
37 3
                    ->addValue($rootNode, 0)
38 3
                    ->build(),
39 3
                $runtime->getValueListFetcher(),
40 3
                $runtime->getEvaluator(),
41 3
                $runtime->getLiteralFactory(),
42 3
                $runtime->getMatcherFactory(),
43
            ];
44
45 3
            return call_user_func($callback, ...$args);
46 1
        } catch (Throwable $e) {
47 1
            throw new Exception\QueryExecutionFailedException(
48 1
                $this->source,
49 1
                $this->callbackBuilder->getCallbackCode(),
50
                $e,
51
            );
52
        }
53
    }
54
55 1
    public function getCapabilities(): CapabilitiesInterface
56
    {
57
        return $this
58 1
            ->callbackBuilder
59 1
            ->getCapabilities();
60
    }
61
62 1
    public function getSource(): string
63
    {
64 1
        return $this->source;
65
    }
66
}
67