Mutator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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