Issues (9)

src/Commands/Delete.php (2 issues)

1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\DbSnapshots\Commands\Concerns\AsksForSnapshotName;
7
use Spatie\DbSnapshots\SnapshotRepository;
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
The assignment to $snapShots is dead and can be removed.
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);
0 ignored issues
show
It seems like $name can also be of type string[]; however, parameter $name of Spatie\DbSnapshots\Snaps...epository::findByName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        $snapshot = app(SnapshotRepository::class)->findByName(/** @scrutinizer ignore-type */ $name);
Loading history...
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