Conditions | 4 |
Paths | 8 |
Total Lines | 30 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
14 | 9 | public function run() { |
|
15 | |||
16 | 9 | if (! self::$earnings) { |
|
17 | 1 | self::$earnings = $this->readFile(app_path('database/seeds/movie_earnings.csv')); |
|
18 | 1 | } |
|
19 | |||
20 | // Dump everything into the database, chunked due to amount of data |
||
21 | 9 | foreach (array_chunk(self::$earnings, 199) as $chunk) { |
|
22 | 9 | DB::table('movie_earnings')->insert($chunk); |
|
23 | 9 | } |
|
24 | |||
25 | // Get newest entries ID's to update movie's latest earnings ID's |
||
26 | 9 | $latest = DB::table('movie_earnings')->select([DB::raw('max(id) as maxID'), 'movie_id']) |
|
27 | 9 | ->groupBy('movie_id') |
|
28 | 9 | ->get(); |
|
29 | |||
30 | 9 | $movies = Movie::all(); |
|
31 | |||
32 | /** @var stdClass $earning */ |
||
33 | 9 | foreach ($latest as $earning) { |
|
34 | /** @var Movie $movie */ |
||
35 | 9 | $movie = $movies->find($earning->movie_id); |
|
36 | 9 | $movie->latest_earnings_id = $earning->maxID; |
|
37 | 9 | } |
|
38 | |||
39 | // Save latest earnings ID's |
||
40 | 9 | $movies->map(function (Movie $movie) { |
|
41 | 9 | $movie->save(); |
|
42 | 9 | }); |
|
43 | 9 | } |
|
44 | |||
75 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.