ImportTownsToDatabase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 24
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 3
1
<?php
2
3
namespace UKTowns\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Support\Str;
8
9
class ImportTownsToDatabase extends Command
10
{
11
    protected $signature = 'uk-towns:import
12
    ';
13
14
    protected $description = 'Import towns table to database.';
15
16 2
    public function handle(): int
17
    {
18 2
        $sqlScript = file_get_contents(__DIR__.'/../../storage/uk-towns.sql');
19 2
        if (!$sqlScript) {
20
            $this->error('Script not found.');
21
22
            return 1;
23
        }
24 2
        $sqlScript  = Str::replace('geo_towns', config('uk-towns.tables.towns'), $sqlScript);
25 2
        $sqlScripts = explode('-- statement', $sqlScript);
26 2
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
27 2
        foreach ($sqlScripts as $sqlScript) {
28 2
            DB::statement(trim($sqlScript));
29
        }
30 2
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
31
32 2
        return 0;
33
    }
34
}
35