for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Remorhaz\JSON\Patch\Operation;
use Remorhaz\JSON\Data\Value\NodeValueInterface;
use Remorhaz\JSON\Pointer\Processor\ProcessorInterface as PointerProcessorInterface;
use Remorhaz\JSON\Pointer\Query\QueryInterface as PointerQueryInterface;
final class CopyOperation implements OperationInterface
{
private $index;
private $pathPointer;
private $fromPointer;
public function __construct(
int $index,
PointerQueryInterface $pathPointer,
PointerQueryInterface $fromPointer
) {
$this->index = $index;
$this->pathPointer = $pathPointer;
$this->fromPointer = $fromPointer;
}
public function apply(NodeValueInterface $input, PointerProcessorInterface $pointerProcessor): NodeValueInterface
$selectResult = $pointerProcessor->select($this->fromPointer, $input);
return $pointerProcessor
->add($this->pathPointer, $input, $selectResult->get())
->get();