Completed
Pull Request — master (#12)
by Adam
04:47 queued 01:24
created

Rebuild   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 41
ccs 0
cts 14
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 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
    public function handle()
40
    {
41
        if (!$this->option('verbose')) {
42
            $this->output = new NullOutput;
43
        }
44
45
        $rebuild = new RebuildModels(
46
            new ProgressBar($this->getOutput()),
47
            App::make(Store::class),
48
            $this->output
49
        );
50
51
        $this->call('search:destroy', $this->getArguments());
52
        $rebuild->rebuild();
53
54
        $this->call('search:optimise', $this->getArguments());
55
        $this->info(PHP_EOL.'Search engine rebuild complete.');
56
    }
57
}
58