Issues (9)

src/Commands/Cleanup.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\DbSnapshots\SnapshotRepository;
7
8
class Cleanup extends Command
9
{
10
    protected $signature = 'snapshot:cleanup {--keep=}';
11
12
    protected $description = 'Specify how many snapshots to keep and delete the rest';
13
14
    public function handle()
15
    {
16
        $snapshots = app(SnapshotRepository::class)->getAll();
17
18
        $keep = $this->option('keep');
19
20
        if (! $keep && $keep !== '0') {
21
            $this->warn('No value for option --keep.');
22
23
            return;
24
        }
25
26
        $snapshots->splice($keep)->each(function ($snapshot) {
0 ignored issues
show
$keep of type string is incompatible with the type integer expected by parameter $offset of Illuminate\Support\Collection::splice(). ( Ignorable by Annotation )

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

26
        $snapshots->splice(/** @scrutinizer ignore-type */ $keep)->each(function ($snapshot) {
Loading history...
27
            $snapshot->delete();
28
        });
29
    }
30
}
31