Completed
Push — master ( bd4f67...80ec68 )
by Freek
12s
created

Delete   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 24 4
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\DbSnapshots\SnapshotRepository;
7
use Spatie\DbSnapshots\Commands\Concerns\AsksForSnapshotName;
8
9
class Delete extends Command
10
{
11
    use AsksForSnapshotName;
12
13
    protected $signature = 'snapshot:delete {name?}';
14
15
    protected $description = 'Delete a snapshot.';
16
17
    public function handle()
18
    {
19
        $snapShots = app(SnapshotRepository::class)->getAll();
0 ignored issues
show
Unused Code introduced by
$snapShots is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
21
        if (app(SnapshotRepository::class)->getAll()->isEmpty()) {
22
            $this->warn('No snapshots found. Run `snapshot:create` to create snapshots.');
23
24
            return;
25
        }
26
27
        $name = $this->argument('name') ?: $this->askForSnapshotName();
28
29
        $snapshot = app(SnapshotRepository::class)->findByName($name);
30
31
        if (! $snapshot) {
32
            $this->warn("Snapshot `{$name}` does not exist!");
33
34
            return;
35
        }
36
37
        $snapshot->delete();
38
39
        $this->info("Snapshot `{$snapshot->name}` deleted!");
40
    }
41
}
42