Passed
Push — master ( e343f8...43624f )
by Edward
05:18
created

DeleteMutation::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\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 $paths;
17
18
    public function __construct(PathInterface ...$paths)
19
    {
20
        $this->paths = $paths;
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
        foreach ($this->paths as $path) {
35
            if ($path->contains($event->getPath())) {
36
                return;
37
            }
38
        }
39
        yield $event;
40
    }
41
}
42