Completed
Push — master ( 3f7afa...f839ca )
by Freek
11s queued 10s
created

Cleanup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 2
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 (! $this->option('keep')) {
21
            $this->warn('No value for option --keep.');
22
23
            return;
24
        }
25
26
        $snapshots->splice($keep)->each(function ($snapshot) {
27
            $snapshot->delete();
28
        });
29
    }
30
}
31