Load   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 7
eloc 21
c 6
b 1
f 0
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 7
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} --disk {--latest}';
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
        $useLatestSnapshot = $this->option('latest') ?: false;
34
35
        $name = $useLatestSnapshot
36
            ? $snapShots->last()->name
37
            : ($this->argument('name') ?: $this->askForSnapshotName());
38
39
        $snapshot = app(SnapshotRepository::class)->findByName($name);
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type string[]; however, parameter $name of Spatie\DbSnapshots\Snaps...epository::findByName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $snapshot = app(SnapshotRepository::class)->findByName(/** @scrutinizer ignore-type */ $name);
Loading history...
40
41
        if (! $snapshot) {
42
            $this->warn("Snapshot `{$name}` does not exist!");
43
44
            return;
45
        }
46
47
        $snapshot->load($this->option('connection'));
48
49
        $this->info("Snapshot `{$name}` loaded!");
50
    }
51
}
52