LoadDataToDBCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 54
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 1
A __construct() 0 5 1
1
<?php
2
3
namespace LaraGeoData\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
8
class LoadDataToDBCommand extends Command
9
{
10
    use HasTablesClassesMap, HasSuffixOption;
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'geonames:import:file-to-db
18
        {type : Migration type. }
19
        {file? : Csv file path. }
20
        {--suffix= : Suffix used for specify country if need. }
21
        {--truncate : Truncate table before import. }
22
    ';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Upload data from csv file to DB.';
30
31
    /**
32
     * The filesystem instance.
33
     *
34
     * @var Filesystem
35
     */
36
    protected Filesystem $files;
37
38
    /**
39
     * Create a new command instance.
40
     *
41
     * @param Filesystem $files
42
     *
43
     * @return void
44
     */
45 18
    public function __construct(Filesystem $files)
46
    {
47 18
        parent::__construct();
48
49 18
        $this->files = $files;
50 18
    }
51
52 11
    public function handle()
53
    {
54 11
        $this->makeTableObjectNameByType($this->argument('type'), $this->files)
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...TableObjectNameByType() 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

54
        $this->makeTableObjectNameByType(/** @scrutinizer ignore-type */ $this->argument('type'), $this->files)
Loading history...
55 10
             ->loadData(
56 10
                 $this->argument('file'),
0 ignored issues
show
Bug introduced by
It seems like $this->argument('file') can also be of type array; however, parameter $filePath of LaraGeoData\Database\Tables\GeoTable::loadData() does only seem to accept null|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

56
                 /** @scrutinizer ignore-type */ $this->argument('file'),
Loading history...
57 10
                 $this->getSuffix(),
58 10
                 (bool) $this->option('truncate')
59
             );
60
61 4
        return 0;
62
    }
63
}
64