PullFromSource   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A estimate() 0 3 1
A handle() 0 5 2
A title() 0 3 1
A chunked() 0 4 1
1
<?php
2
3
namespace Matchish\ScoutElasticSearch\Jobs\Stages;
4
5
use Illuminate\Support\Collection;
6
use Matchish\ScoutElasticSearch\Searchable\ImportSource;
7
8
/**
9
 * @internal
10
 */
11
final class PullFromSource
12
{
13
    /**
14
     * @var ImportSource
15
     */
16
    private $source;
17
18
    /**
19
     * @param ImportSource $source
20
     */
21 17
    public function __construct(ImportSource $source)
22
    {
23 17
        $this->source = $source;
24 17
    }
25
26 16
    public function handle(): void
27
    {
28 16
        $results = $this->source->get()->filter->shouldBeSearchable();
29 16
        if (! $results->isEmpty()) {
30 15
            $results->first()->searchableUsing()->update($results);
31
        }
32 16
    }
33
34 10
    public function estimate(): int
35
    {
36 10
        return 1;
37
    }
38
39 10
    public function title(): string
40
    {
41 10
        return 'Indexing...';
42
    }
43
44
    /**
45
     * @param ImportSource $source
46
     * @return Collection
47
     */
48 18
    public static function chunked(ImportSource $source): Collection
49
    {
50
        return $source->chunked()->map(function ($chunk) {
51 13
            return new static($chunk);
52 18
        });
53
    }
54
}
55