ProvincesTableSeeder::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 19
c 0
b 0
f 0
rs 9.7666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Turahe\Master\Seeds;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Seeder;
7
use Turahe\Master\Models\Province;
8
9
class ProvincesTableSeeder extends Seeder
10
{
11
    public function run()
12
    {
13
        $now = Carbon::now();
14
        $csv = new CsvtoArray();
15
        $file = __DIR__.'/../../resources/csv/provinces.csv';
16
        $header = ['id', 'name', 'lat', 'long'];
17
        $data = $csv->csv_to_array($file, $header);
18
        $provinces = array_map(function ($arr) use ($now) {
19
            return [
20
                'country_id' => 104,
21
                'name' => $arr['name'],
22
                'latitude' => $arr['lat'],
23
                'longitude' => $arr['long'],
24
                'created_at' => $now,
25
                'updated_at' => $now,
26
            ];
27
        }, $data);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type false; however, parameter $arr1 of array_map() does only seem to accept array, 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

27
        }, /** @scrutinizer ignore-type */ $data);
Loading history...
28
29
        Province::insert($provinces);
30
    }
31
}
32