ListSnapshots::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 19
rs 9.9332
cc 2
nc 2
nop 0
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