Completed
Push — master ( 99577b...901a4d )
by Freek
03:36
created

Create   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 3
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use DB;
6
use Carbon\Carbon;
7
use Illuminate\Console\Command;
8
use Spatie\DbSnapshots\Helpers\Format;
9
use Spatie\DbSnapshots\SnapshotFactory;
10
use Illuminate\Console\ConfirmableTrait;
11
12
class Create extends Command
13
{
14
    protected $signature = 'snapshot:create {name?} {--connection}';
15
16
    protected $description = 'Create a new snapshot.';
17
18
    public function handle()
19
    {
20
        $this->info('Creating new snapshot...');
21
22
        $connectionName = $this->option('connection')
23
            ?: config('db-snapshots.default_connection')
24
            ?? config('database.default');
25
26
        $snapshotName = $this->argument('name') ?: Carbon::now()->format('Y-m-d H:i:s');
27
28
        $snapshot = app(SnapshotFactory::class)->create(
29
            $snapshotName,
30
            config('db-snapshots.disk'),
31
            $connectionName
32
        );
33
34
        $size = Format::humanReadableSize($snapshot->size());
35
36
        $this->info("Snapshot `{$snapshotName}` created (size: {$size})");
37
    }
38
}
39