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

DeleteMutation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 27
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A reset() 0 2 1
A __invoke() 0 3 1
A createEventGenerator() 0 8 3
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