ListSnapshots   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 3
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 2
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\DbSnapshots\Helpers\Format;
7
use Spatie\DbSnapshots\Snapshot;
8
use Spatie\DbSnapshots\SnapshotRepository;
9
10
class ListSnapshots extends Command
11
{
12
    protected $signature = 'snapshot:list';
13
14
    protected $description = 'List all the snapshots.';
15
16
    public function handle()
17
    {
18
        $snapshots = app(SnapshotRepository::class)->getAll();
19
20
        if ($snapshots->isEmpty()) {
21
            $this->warn('No snapshots found. Run `snapshot:create` to create one.');
22
23
            return;
24
        }
25
26
        $rows = $snapshots->map(function (Snapshot $snapshot) {
27
            return [
28
                $snapshot->name,
29
                $snapshot->createdAt()->format('Y-m-d H:i:s'),
30
                Format::humanReadableSize($snapshot->size()),
31
            ];
32
        });
33
34
        $this->table(['Name', 'Created at', 'Size'], $rows);
35
    }
36
}
37