Issues (9)

src/Commands/Create.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
use Spatie\DbSnapshots\Helpers\Format;
8
use Spatie\DbSnapshots\SnapshotFactory;
9
10
class Create extends Command
11
{
12
    protected $signature = 'snapshot:create {name?} {--connection=} {--compress}';
13
14
    protected $description = 'Create a new snapshot.';
15
16
    public function handle()
17
    {
18
        $this->info('Creating new snapshot...');
19
20
        $connectionName = $this->option('connection')
21
            ?: config('db-snapshots.default_connection')
22
            ?? config('database.default');
23
24
        $snapshotName = $this->argument('name') ?: Carbon::now()->format('Y-m-d_H-i-s');
25
26
        $compress = $this->option('compress') || config('db-snapshots.compress', false);
27
28
        $snapshot = app(SnapshotFactory::class)->create(
29
            $snapshotName,
0 ignored issues
show
It seems like $snapshotName can also be of type string[]; however, parameter $snapshotName of Spatie\DbSnapshots\SnapshotFactory::create() 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

29
            /** @scrutinizer ignore-type */ $snapshotName,
Loading history...
30
            config('db-snapshots.disk'),
31
            $connectionName,
32
            $compress
33
        );
34
35
        $size = Format::humanReadableSize($snapshot->size());
36
37
        $this->info("Snapshot `{$snapshotName}` created (size: {$size})");
38
    }
39
}
40