Passed
Push — master ( ec8827...deea55 )
by Edward
02:26
created

Query   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 2
A __construct() 0 8 1
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
    public function __construct(
24
        ValueEncoderInterface $encoder,
25
        ValueDecoderInterface $decoder,
26
        OperationInterface ...$operations
27
    ) {
28
        $this->encoder = $encoder;
29
        $this->decoder = $decoder;
30
        $this->operations = $operations;
31
    }
32
33
    public function __invoke(NodeValueInterface $data, PointerProcessorInterface $pointerProcessor): ResultInterface
34
    {
35
        $output = $data;
36
        foreach ($this->operations as $operation) {
37
            $output = $operation->apply($output, $pointerProcessor);
38
        }
39
40
        return new Result($output, $this->encoder, $this->decoder);
41
    }
42
}
43