CountriesSeeder::run()   D
last analyzed

Complexity

Conditions 10
Paths 2

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
rs 4.8196
cc 10
eloc 22
nc 2
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 App\Containers\Country\Data\Seeders;
4
5
use App\Ship\Parents\Seeders\Seeder;
6
use Webpatser\Countries\CountriesFacade as Countries;
7
8
/**
9
 * Class CountriesSeeder
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
class CountriesSeeder extends Seeder
14
{
15
16
    /**
17
     * Run the database seeds.
18
     *
19
     * @return  void
20
     */
21
    public function run()
22
    {
23
24
        //Empty the countries table
25
        \DB::table(\Config::get('countries.table_name'))->delete();
26
27
        //Get all of the countries
28
        $countries = Countries::getList();
29
        foreach ($countries as $countryId => $country) {
30
            \DB::table(\Config::get('countries.table_name'))->insert(array(
31
                'id'                => $countryId,
32
                'capital'           => ((isset($country['capital'])) ? $country['capital'] : null),
33
                'citizenship'       => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
34
                'country_code'      => $country['country-code'],
35
                'currency'          => ((isset($country['currency'])) ? $country['currency'] : null),
36
                'currency_code'     => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
37
                'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
38
                'full_name'         => ((isset($country['full_name'])) ? $country['full_name'] : null),
39
                'iso_3166_2'        => $country['iso_3166_2'],
40
                'iso_3166_3'        => $country['iso_3166_3'],
41
                'name'              => $country['name'],
42
                'region_code'       => $country['region-code'],
43
                'sub_region_code'   => $country['sub-region-code'],
44
                'eea'               => (bool)$country['eea'],
45
                'calling_code'      => $country['calling_code'],
46
                'currency_symbol'   => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
47
                'flag'              => ((isset($country['flag'])) ? $country['flag'] : null),
48
            ));
49
        }
50
    }
51
}
52