DistrictsTableSeeder::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 Illuminate\Database\Seeder;
6
use Turahe\Master\Models\District;
7
8
class DistrictsTableSeeder extends Seeder
9
{
10
    public function run()
11
    {
12
        $now = now()->toDateTimeString();
13
        $csv = new CsvtoArray();
14
        $file = __DIR__.'/../../resources/csv/districts.csv';
15
        $header = ['id', 'city_id', 'name', 'lat', 'long'];
16
        $data = $csv->csv_to_array($file, $header);
17
        $districts = array_map(function ($arr) use ($now) {
18
            return [
19
                'name' => $arr['name'],
20
                'city_id' => $arr['city_id'],
21
                'latitude' => $arr['lat'],
22
                'longitude' => $arr['long'],
23
                'created_at' => $now,
24
                'updated_at' => $now,
25
            ];
26
        }, $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

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