FlushCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 1
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Matchish\ScoutElasticSearch\Console\Commands;
6
7
use Illuminate\Console\Command;
8
use Matchish\ScoutElasticSearch\Searchable\SearchableListFactory;
9
10
final class FlushCommand extends Command
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $signature = 'scout:flush {searchable?* : The name of the searchable}';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $description = 'Flush the index of the the given searchable';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public function handle(): void
26
    {
27 1
        $command = $this;
28
        $searchableList = collect($command->argument('searchable'))->whenEmpty(function () {
29 1
            $factory = new SearchableListFactory(app()->getNamespace(), app()->path());
0 ignored issues
show
introduced by
The method getNamespace() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
            $factory = new SearchableListFactory(app()->/** @scrutinizer ignore-call */ getNamespace(), app()->path());
Loading history...
introduced by
The method path() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
            $factory = new SearchableListFactory(app()->getNamespace(), app()->/** @scrutinizer ignore-call */ path());
Loading history...
30
31 1
            return $factory->make();
32 1
        });
33
        $searchableList->each(function ($searchable) {
34 1
            $searchable::removeAllFromSearch();
35 1
            $doneMessage = trans('scout::flush.done', [
36 1
                'searchable' => $searchable,
37
            ]);
38 1
            $this->output->success($doneMessage);
39 1
        });
40 1
    }
41
}
42