Completed
Pull Request — master (#79)
by
unknown
03:29
created

Cleanup::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 0
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