Import::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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