ImportCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Leitom\Geo\Console;
4
5
use Illuminate\Console\Command;
6
use Leitom\Geo\Events\ModelsImported;
7
use Illuminate\Contracts\Events\Dispatcher;
8
9 View Code Duplication
class ImportCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    protected $signature = 'geo:import {model}';
12
13
    protected $description = 'Import all records from the given model into the redis index';
14
15
    public function handle(Dispatcher $events)
16
    {
17
        $class = $this->argument('model');
18
19
        $model = new $class;
20
21
        $events->listen(ModelsImported::class, function ($event) use ($class) {
22
            $key = $event->models->last()->geoKey();
23
            $this->line('<comment>Imported ['.$class.'] models up to ID:</comment> '.$key);
24
        });
25
26
        $model::geoImportAll();
27
28
        $events->forget(ModelsImported::class);
29
30
        $this->info('All ['.$class.'] records have been imported.');
31
    }
32
}
33