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

MoveOperation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Patch\Operation;
5
6
use Remorhaz\JSON\Data\Value\NodeValueInterface;
7
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
8
use Remorhaz\JSON\Pointer\Query\QueryInterface as PointerQueryInterface;
9
10
final class MoveOperation implements OperationInterface
11
{
12
13
    private $index;
14
15
    private $pathPointer;
16
17
    private $fromPointer;
18
19
    public function __construct(
20
        int $index,
21
        PointerQueryInterface $pathPointer,
22
        PointerQueryInterface $fromPointer
23
    ) {
24
        $this->index = $index;
25
        $this->pathPointer = $pathPointer;
26
        $this->fromPointer = $fromPointer;
27
    }
28
29
    public function apply(NodeValueInterface $input, PointerProcessorInterface $pointerProcessor): NodeValueInterface
30
    {
31
        $selectResult = $pointerProcessor->select($this->fromPointer, $input);
32
        $deleteResult = $pointerProcessor->delete($this->fromPointer, $input);
33
34
        return $pointerProcessor
35
            ->add($this->pathPointer, $deleteResult->get(), $selectResult->get())
36
            ->get();
37
    }
38
}
39