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

Processor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Remorhaz\JSON\Patch\Processor;
4
5
use Remorhaz\JSON\Data\Value\NodeValueInterface;
6
use Remorhaz\JSON\Patch\Query\QueryInterface;
7
use Remorhaz\JSON\Patch\Result\ResultInterface;
8
use Remorhaz\JSON\Pointer\Processor\Processor as PointerProcessor;
9
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
10
use Throwable;
11
12
class Processor implements ProcessorInterface
13
{
14
15
    private $pointerProcessor;
16
17
    public static function create(): ProcessorInterface
18
    {
19
        return new self(PointerProcessor::create());
20
    }
21
22
    public function __construct(PointerProcessorInterface $pointerProcessor)
23
    {
24
        $this->pointerProcessor = $pointerProcessor;
25
    }
26
27
    public function apply(QueryInterface $query, NodeValueInterface $data): ResultInterface
28
    {
29
        try {
30
            return $query($data, $this->pointerProcessor);
31
        } catch (Throwable $e) {
32
            throw new Exception\PatchNotAppliedException($e);
33
        }
34
    }
35
}
36