Import   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A stages() 0 3 1
A __construct() 0 3 1
A handle() 0 9 1
1
<?php
2
3
namespace Matchish\ScoutElasticSearch\Jobs;
4
5
use Elasticsearch\Client;
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Support\Collection;
8
use Matchish\ScoutElasticSearch\ProgressReportable;
9
use Matchish\ScoutElasticSearch\Searchable\ImportSource;
10
11
/**
12
 * @internal
13
 */
14
final class Import
15
{
16
    use Queueable;
17
    use ProgressReportable;
18
19
    /**
20
     * @var ImportSource
21
     */
22
    private $source;
23
24
    /**
25
     * @param ImportSource $source
26
     */
27 13
    public function __construct(ImportSource $source)
28
    {
29 13
        $this->source = $source;
30 13
    }
31
32
    /**
33
     * @param Client $elasticsearch
34
     */
35 13
    public function handle(Client $elasticsearch): void
36
    {
37 13
        $stages = $this->stages();
38 13
        $estimate = $stages->sum->estimate();
39 13
        $this->progressBar()->setMaxSteps($estimate);
40
        $stages->each(function ($stage) use ($elasticsearch) {
41 13
            $this->progressBar()->setMessage($stage->title());
42 13
            $stage->handle($elasticsearch);
43 13
            $this->progressBar()->advance($stage->estimate());
44 13
        });
45 13
    }
46
47 13
    private function stages(): Collection
48
    {
49 13
        return ImportStages::fromSource($this->source);
50
    }
51
}
52