Issues (52)

src/Seeds/VillagesTableSeeder.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Turahe\Master\Seeds;
4
5
use Illuminate\Database\Seeder;
6
use Illuminate\Support\Facades\File;
7
use Turahe\Master\Models\Village;
8
9
class VillagesTableSeeder extends Seeder
10
{
11
    public function run()
12
    {
13
        $now = now()->toDateTimeString();
14
        $csv = new CsvtoArray();
15
        $resourceFiles = File::allFiles(__DIR__.'/../../resources/csv/villages');
16
        foreach ($resourceFiles as $file) {
17
            $header = ['id', 'district_id', 'name', 'lat', 'long'];
18
            $data = $csv->csv_to_array($file->getRealPath(), $header);
19
20
            $villages = array_map(function ($arr) use ($now) {
21
                return [
22
                    'district_id' => $arr['district_id'],
23
                    'name' => $arr['name'],
24
                    'latitude' => $arr['lat'],
25
                    'longitude' => $arr['long'],
26
                    'created_at' => $now,
27
                    'updated_at' => $now,
28
                ];
29
            }, $data);
0 ignored issues
show
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

29
            }, /** @scrutinizer ignore-type */ $data);
Loading history...
30
31
            Village::insert($villages);
32
        }
33
    }
34
}
35