Completed
Pull Request — master (#93)
by Peter
01:12
created

Load   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 32 6
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Spatie\DbSnapshots\Commands\Concerns\AsksForSnapshotName;
8
use Spatie\DbSnapshots\SnapshotRepository;
9
10
class Load extends Command
11
{
12
    use AsksForSnapshotName;
13
    use ConfirmableTrait;
14
15
    protected $signature = 'snapshot:load {name?} {--connection=} {--force} {--stream} --disk';
16
17
    protected $description = 'Load up a snapshot.';
18
19
    public function handle()
20
    {
21
        $snapShots = app(SnapshotRepository::class)->getAll();
22
23
        if ($snapShots->isEmpty()) {
24
            $this->warn('No snapshots found. Run `snapshot:create` first to create snapshots.');
25
26
            return;
27
        }
28
29
        if (! $this->confirmToProceed()) {
30
            return;
31
        }
32
33
        $name = $this->argument('name') ?: $this->askForSnapshotName();
34
35
        $snapshot = app(SnapshotRepository::class)->findByName($name);
36
37
        if (! $snapshot) {
38
            $this->warn("Snapshot `{$name}` does not exist!");
39
40
            return;
41
        }
42
43
        if ($this->option('stream')) {
44
            $snapshot->loadStream($this->option('connection'));
45
        } else {
46
            $snapshot->load($this->option('connection'));
47
        }
48
49
        $this->info("Snapshot `{$name}` loaded!");
50
    }
51
}
52