Code Duplication    Length = 33-37 lines in 2 locations

src/Console/RebuildProjectorCommand.php 1 location

@@ 10-46 (lines=37) @@
7
use Spatie\EventProjector\Console\Concerns\ReplaysEvents;
8
use Spatie\EventProjector\EventProjectionist;
9
10
class RebuildProjectorCommand extends Command
11
{
12
    use ReplaysEvents;
13
14
    protected $signature = 'event-projector:rebuild-projector {projectorName*}';
15
16
    protected $description = 'Rebuild a projector';
17
18
    /** @var \Spatie\EventProjector\EventProjectionist */
19
    protected $eventProjectionist;
20
21
    public function __construct(EventProjectionist $eventProjectionist)
22
    {
23
        parent::__construct();
24
25
        $this->eventProjectionist = $eventProjectionist;
26
    }
27
28
    public function handle()
29
    {
30
        $projectorNames = $this->argument('projectorName');
31
32
        $projectors = collect($projectorNames)
33
            ->map(function (string $projectorName) {
34
                if (!$projector = $this->eventProjectionist->getProjector($projectorName)) {
35
                    throw new Exception("Projector {$projectorName} not found. Did you register?");
36
                }
37
38
                return $projector;
39
            })
40
            ->each->reset();
41
42
        $this->replayEvents($projectors);
43
44
        $this->comment('Projector(s) rebuild!');
45
    }
46
}
47

src/Console/ResetProjectorCommand.php 1 location

@@ 10-42 (lines=33) @@
7
use Spatie\EventProjector\EventProjectionist;
8
use Spatie\EventProjector\Console\Snapshots\Concerns\ChooseSnapshot;
9
10
class ResetProjectorCommand extends Command
11
{
12
    protected $signature = 'event-projector:reset-projector {projectorName*}';
13
14
    protected $description = 'Reset a projector';
15
16
    /** @var \Spatie\EventProjector\EventProjectionist */
17
    protected $eventProjectionist;
18
19
    public function __construct(EventProjectionist $eventProjectionist)
20
    {
21
        parent::__construct();
22
23
        $this->eventProjectionist = $eventProjectionist;
24
    }
25
26
    public function handle()
27
    {
28
        $projectorNames = $this->argument('projectorName');
29
30
        collect($projectorNames)
31
            ->map(function (string $projectorName) {
32
                if (!$projector = $this->eventProjectionist->getProjector($projectorName)) {
33
                    throw new Exception("Projector {$projectorName} not found. Did you register?");
34
                }
35
36
                return $projector;
37
            })
38
            ->each->reset();
39
40
        $this->comment('Projector(s) reset!');
41
    }
42
}
43