ParseVocabulary   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 17 1
1
<?php
2
3
namespace App\Jobs;
4
5
use App\Events\ImportParseFinished;
6
use App\Models\Import;
7
use App\Services\Import\DataImporter;
8
use App\Services\Import\GoogleSpreadsheet;
9
use Illuminate\Bus\Queueable;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Foundation\Bus\Dispatchable;
12
use Illuminate\Queue\InteractsWithQueue;
13
use Illuminate\Queue\SerializesModels;
14
use const EXTR_OVERWRITE;
15
use function collect;
16
use function extract;
17
18
class ParseVocabulary implements ShouldQueue
19
{
20
    use InteractsWithQueue, Queueable, SerializesModels, Dispatchable;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Jobs\ParseVocabulary: $id, $class
Loading history...
21
    /**
22
     * @var Import
23
     */
24
    private $import;
25
    /**
26
     * @var string
27
     */
28
    private $worksheet_id;
29
    /**
30
     * @var array
31
     */
32
    private $spreadsheet;
33
34
    public function __construct(Import $import, string $worksheet_id, array $spreadsheet)
35
    {
36
        $this->import       = $import;
37
        $this->worksheet_id = $worksheet_id;
38
        $this->spreadsheet  = $spreadsheet;
39
    }
40
41
    /**
42
     * Execute the job.
43
     */
44
    public function handle()
45
    {
46
        $source_file_name = '';
47
        $import_type      = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $import_type is dead and can be removed.
Loading history...
48
        extract($this->spreadsheet, EXTR_OVERWRITE);
49
        $sheet    = new GoogleSpreadsheet($source_file_name);
50
        $data     = collect($sheet->getWorksheetData($this->worksheet_id)->toArray());
51
        //TODO: Handle $import_type in the importer
52
        $importer = new DataImporter($data, $this->import->export);
53
        //then we pass them to the importer
54
        $changeSet                  = $importer->getChangeset();
55
        $this->import->instructions = $changeSet;
0 ignored issues
show
Documentation Bug introduced by
It seems like $changeSet of type Illuminate\Support\Collection is incompatible with the declared type array of property $instructions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $this->import->preprocess   = $importer->getStats();
0 ignored issues
show
Documentation Bug introduced by
It seems like $importer->getStats() of type Illuminate\Support\Collection is incompatible with the declared type array of property $preprocess.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->import->errors       = $importer->getErrors()->toJson();
58
        $this->import->save();
59
60
        event(new ImportParseFinished($this->import));
61
    }
62
}
63