Passed
Push — master ( f90e65...c97d58 )
by Yaroslav
04:32
created

MakeMigrationCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace LaraGeoData\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Str;
8
9
class MakeMigrationCommand extends Command
10
{
11
    use HasTablesClassesMap;
12
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'geonames:make:migration
19
        {type : Migration type. }
20
        {--suffix= : Suffix used for specify country if need. }
21
    ';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Publish specific migrations.';
29
30
    /**
31
     * The filesystem instance.
32
     *
33
     * @var Filesystem
34
     */
35
    protected Filesystem $files;
36
37
    /**
38
     * Create a new command instance.
39
     *
40
     * @param Filesystem $files
41
     *
42
     * @return void
43
     */
44 18
    public function __construct(Filesystem $files)
45
    {
46 18
        parent::__construct();
47
48 18
        $this->files = $files;
49 18
    }
50
51 11
    public function handle()
52
    {
53 11
        $tableClassName = $this->getTableClassNameByType($this->argument('type'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('type') can also be of type array and null; however, parameter $type of LaraGeoData\Console\Comm...tTableClassNameByType() 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

53
        $tableClassName = $this->getTableClassNameByType(/** @scrutinizer ignore-type */ $this->argument('type'));
Loading history...
54
55 11
        (new $tableClassName($this->files))->makeMigration($this->getSuffix());
56
57 11
        return 0;
58
    }
59
60
    /**
61
     * Get formatted suffix.
62
     *
63
     * @return string|null
64
     */
65 11
    protected function getSuffix(): ?string
66
    {
67 11
        $suffix = $this->option('suffix');
68 11
        if ($suffix) {
69 8
            $suffix = Str::snake($suffix);
70
        }
71
72 11
        return $suffix;
73
    }
74
}
75