Completed
Push — master ( 91b636...82125a )
by Freek
01:52
created

DeleteSnapshotCommand::displaySnapshots()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 9
Ratio 56.25 %

Importance

Changes 0
Metric Value
dl 9
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace Spatie\EventProjector\Console\Snapshots;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Spatie\EventProjector\Console\Snapshots\Concerns\ChooseSnapshot;
8
use Spatie\EventProjector\Snapshots\Snapshot;
9
use Spatie\EventProjector\Snapshots\SnapshotRepository;
10
11 View Code Duplication
class DeleteSnapshotCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    use ChooseSnapshot;
14
15
    protected $signature = 'event-projector:delete-snapshot';
16
17
    protected $description = 'Delete a snapshot';
18
19
    /** @var \Spatie\EventProjector\Snapshots\SnapshotRepository */
20
    protected $snapshotRepository;
21
22
    public function __construct(SnapshotRepository $snapshotRepository)
23
    {
24
        parent::__construct();
25
26
        $this->snapshotRepository = $snapshotRepository;
27
    }
28
29
    public function handle()
30
    {
31
        $snapshots = $this->snapshotRepository->get();
32
33
        $snapshot = $this->chooseSnapshot('Which snapshot number would like to delete?', $snapshots);
34
35
        if (! $snapshot) {
36
            return;
37
        }
38
39
        $snapshot->delete();
40
41
        $this->comment("Snapshot deleted!");
42
    }
43
}
44