DeleteMutation::createEventGenerator()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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