Query::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Patch\Query;
5
6
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
7
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
8
use Remorhaz\JSON\Data\Value\NodeValueInterface;
9
use Remorhaz\JSON\Patch\Operation\OperationInterface;
10
use Remorhaz\JSON\Patch\Result\Result;
11
use Remorhaz\JSON\Patch\Result\ResultInterface;
12
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
13
14
final class Query implements QueryInterface
15
{
16
17
    private $encoder;
18
19
    private $decoder;
20
21
    private $operations;
22
23 8
    public function __construct(
24
        ValueEncoderInterface $encoder,
25
        ValueDecoderInterface $decoder,
26
        OperationInterface ...$operations
27
    ) {
28 8
        $this->encoder = $encoder;
29 8
        $this->decoder = $decoder;
30 8
        $this->operations = $operations;
31 8
    }
32
33 8
    public function __invoke(NodeValueInterface $data, PointerProcessorInterface $pointerProcessor): ResultInterface
34
    {
35 8
        $output = $data;
36 8
        foreach ($this->operations as $operation) {
37 5
            $output = $operation->apply($output, $pointerProcessor);
38
        }
39
40 8
        return new Result($output, $this->encoder, $this->decoder);
41
    }
42
}
43