Passed
Push — master ( 3a32e2...77143f )
by Edward
04:21
created

DeleteMutation::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Pointer\Processor\Mutator;
5
6
use Generator;
7
use Iterator;
8
use Remorhaz\JSON\Data\Event\EventInterface;
9
use Remorhaz\JSON\Data\Path\PathInterface;
10
use Remorhaz\JSON\Data\Walker\MutationInterface;
11
use Remorhaz\JSON\Data\Walker\ValueWalkerInterface;
12
13
final class DeleteMutation implements MutationInterface
14
{
15
16
    private $path;
17
18
    public function __construct(PathInterface $path)
19
    {
20
        $this->path = $path;
21
    }
22
23
    public function __invoke(EventInterface $event, ValueWalkerInterface $valueWalker): Iterator
24
    {
25
        return $this->createEventGenerator($event);
26
    }
27
28
    public function reset(): void
29
    {
30
    }
31
32
    private function createEventGenerator(EventInterface $event): Generator
33
    {
34
        if ($this->path->contains($event->getPath())) {
35
            return;
36
        }
37
        yield $event;
38
    }
39
}
40