CountriesTableSeeder::run()   B
last analyzed

Complexity

Conditions 10
Paths 1

Size

Total Lines 28
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 28
rs 7.6666
c 0
b 0
f 0
cc 10
nc 1
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Turahe\Master\Seeds;
4
5
use Illuminate\Database\Seeder;
6
use Turahe\Master\Models\Country;
7
8
class CountriesTableSeeder extends Seeder
9
{
10
    /**
11
     * Run the database seeds.
12
     *
13
     * @return void
14
     */
15
    public function run()
16
    {
17
        $file = __DIR__.'/../../resources/countries.json';
18
        $data = json_decode(file_get_contents($file), true);
19
        $countries = array_map(function ($country) {
20
            return [
21
                'capital' => $country['capital'] ?? null,
22
                'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
23
                'country_code' => $country['country-code'],
24
                'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
25
                'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
26
                'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
27
                'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
28
                'iso_3166_2' => $country['iso_3166_2'],
29
                'iso_3166_3' => $country['iso_3166_3'],
30
                'name' => $country['name'],
31
                'region_code' => (isset($country['region-code'])) ? $country['region-code'] : null, //$country['region-code'],
32
                'sub_region_code' => (isset($country['sub-region-code'])) ? $country['sub-region-code'] : null, //$country['sub-region-code'],
33
                'eea' => (bool) $country['eea'],
34
                'calling_code' => $country['calling_code'],
35
                'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
36
                'flag' =>((isset($country['flag'])) ? $country['flag'] : null),
37
                'created_at' => now()->toDateTimeString(),
38
                'updated_at' => now()->toDateTimeString(),
39
            ];
40
        }, $data);
41
42
        Country::insert($countries);
43
    }
44
}
45