| Conditions | 4 |
| Paths | 2 |
| Total Lines | 30 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function handle($importer) |
||
| 14 | { |
||
| 15 | $failed = collect(); |
||
| 16 | $created = collect(); |
||
| 17 | $updated = collect(); |
||
| 18 | |||
| 19 | $importer->each(function(CellCollection $row) use($importer, &$failed, &$created, &$updated) { |
||
| 20 | $fillable = $row->intersectByKeys(array_flip(app($importer->config['resource'])->getFillable()))->toArray(); |
||
| 21 | |||
| 22 | try { |
||
| 23 | $record = tap(app($importer->config['resource'])->firstOrNew($fillable), function ($instance) { |
||
| 24 | $instance->save(); |
||
| 25 | }); |
||
| 26 | |||
| 27 | $record->wasRecentlyCreated |
||
| 28 | ? $created->push($record->{$importer->config['name']}) |
||
| 29 | : $updated->push($record->{$importer->config['name']}); |
||
| 30 | } catch (Exception $e) { |
||
| 31 | $failed->push($record->{$importer->config['name']}); |
||
| 32 | } |
||
| 33 | }); |
||
| 34 | |||
| 35 | ! $importer->config['log'] || activity() |
||
| 36 | ->performedOn(app($importer->config['resource'])) |
||
| 37 | ->withProperties([ |
||
| 38 | 'count' => ['created' => $created->count(), 'updated' => $updated->count(), 'failed' => $failed->count()], |
||
|
|
|||
| 39 | 'names' => ['created' => $created, 'updated' => $updated, 'failed' => $failed]] |
||
| 40 | ) |
||
| 41 | ->log('imported'); |
||
| 42 | } |
||
| 43 | } |
||
| 44 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.