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

AddOperation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A apply() 0 5 1
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 AddOperation implements OperationInterface
11
{
12
13
    private $index;
14
15
    private $pathPointer;
16
17
    private $value;
18
19
    public function __construct(
20
        int $index,
21
        PointerQueryInterface $pathPointer,
22
        NodeValueInterface $value
23
    ) {
24
        $this->index = $index;
25
        $this->pathPointer = $pathPointer;
26
        $this->value = $value;
27
    }
28
29
    public function apply(NodeValueInterface $input, PointerProcessorInterface $pointerProcessor): NodeValueInterface
30
    {
31
        return $pointerProcessor
32
            ->add($this->pathPointer, $input, $this->value)
33
            ->get();
34
    }
35
}
36