Processor::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
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 6
ccs 4
cts 4
cp 1
crap 2
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 3
    public static function create(): ProcessorInterface
18
    {
19 3
        return new self(PointerProcessor::create());
20
    }
21
22 4
    public function __construct(PointerProcessorInterface $pointerProcessor)
23
    {
24 4
        $this->pointerProcessor = $pointerProcessor;
25 4
    }
26
27 3
    public function apply(QueryInterface $query, NodeValueInterface $data): ResultInterface
28
    {
29
        try {
30 3
            return $query($data, $this->pointerProcessor);
31 1
        } catch (Throwable $e) {
32 1
            throw new Exception\PatchNotAppliedException($e);
33
        }
34
    }
35
}
36