Rebuild::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 0
crap 2
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Laravel\Console;
4
5
use BestServedCold\LaravelZendSearch\Laravel\RebuildModels;
6
use BestServedCold\LaravelZendSearch\Laravel\Store;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\App;
9
use Symfony\Component\Console\Helper\ProgressBar;
10
use Symfony\Component\Console\Output\NullOutput;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Class RebuildCommand
15
 * @package BestServedCold\LaravelZendSearch\Laravel\Console
16
 */
17
class Rebuild extends Command
18
{
19
    /**
20
     * @var string $name
21
     */
22
    protected $name = 'search:rebuild';
23
24
    /**
25
     * @var string $description
26
     */
27
    protected $description = 'Rebuild the search index';
28
29
    /**
30
     * @var OutputInterface
31
     */
32
    protected $output;
33
34
    /**
35
     * Handle
36
     *
37
     * @return void
38
     */
39 3
    public function handle()
40
    {
41 3
        if (!$this->option('verbose')) {
42 1
            $this->output = new NullOutput;
43 1
        }
44
45 3
        $rebuild = new RebuildModels(
46 3
            new ProgressBar($this->getOutput()),
47 3
            App::make(Store::class),
48 3
            $this->output
49 3
        );
50
51 3
        $this->call('search:destroy', $this->getArguments());
52 3
        $rebuild->rebuild();
53
54 3
        $this->call('search:optimise', $this->getArguments());
55 3
        $this->info(PHP_EOL.'Search engine rebuild complete.');
56 3
    }
57
}
58