Passed
Push — master ( 3d52a7...3a32e2 )
by Edward
02:11
created

Mutator::mutate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Pointer\Processor\Mutator;
5
6
use Remorhaz\JSON\Data\Export\EventDecoderInterface;
7
use Remorhaz\JSON\Data\Path\Path;
8
use Remorhaz\JSON\Data\Value\NodeValueInterface;
9
use Remorhaz\JSON\Data\Walker\MutationInterface;
10
use Remorhaz\JSON\Data\Walker\ValueWalkerInterface;
11
12
final class Mutator implements MutatorInterface
13
{
14
15
    private $valueWalker;
16
17
    private $eventDecoder;
18
19 5
    public function __construct(ValueWalkerInterface $valueWalker, EventDecoderInterface $eventDecoder)
20
    {
21 5
        $this->valueWalker = $valueWalker;
22 5
        $this->eventDecoder = $eventDecoder;
23 5
    }
24
25 5
    public function mutate(NodeValueInterface $rootNode, MutationInterface $mutation): ?NodeValueInterface
26
    {
27
        $events = $this
28 5
            ->valueWalker
29 5
            ->createMutableEventIterator($rootNode, new Path, $mutation);
30
31
        return $this
32 5
            ->eventDecoder
33 5
            ->exportEvents($events);
34
    }
35
}
36