Test Failed
Push — develop ( 63ed01...7218b8 )
by Nuno
05:28
created

StatusCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 54
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 39 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended\Console\Commands;
15
16
use function count;
17
use Laravel\Scout\Searchable;
18
use Illuminate\Console\Command;
19
use Algolia\ScoutExtended\Algolia;
20
use Algolia\ScoutExtended\Settings\Synchronizer;
21
use Algolia\ScoutExtended\Helpers\SearchableFinder;
22
use Algolia\ScoutExtended\Searchable\RecordsCounter;
23
24
final class StatusCommand extends Command
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected $signature = 'scout:status {searchable? : The name of the searchable}';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected $description = 'Show the status of the index of the the given searchable';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function handle(
40
        Algolia $algolia,
41
        SearchableFinder $searchableFinder,
42
        Synchronizer $synchronizer,
43
        RecordsCounter $recordsCounter
44
    ): void {
45 1
        $searchables = $searchableFinder->fromCommand($this);
46
47 1
        $rows = [];
48
49 1
        $this->output->text('🔎 Analysing information from: <info>['.implode(',', $searchables).']</info>');
50 1
        $this->output->newLine();
51 1
        $this->output->progressStart(count($searchables));
52
53 1
        foreach ($searchables as $searchable) {
54 1
            $row = [];
55 1
            $instance = $this->laravel->make($searchable);
56 1
            $index = $algolia->index($instance);
57 1
            $row[] = $searchable;
58 1
            $row[] = $instance->searchableAs();
59
60 1
            $status = $synchronizer->analyse($index);
61 1
            $description = $status->toHumanString();
62 1
            if (! $status->bothAreEqual()) {
63 1
                $description = "<fg=red>$description</>";
64
            } else {
65
                $description = '<fg=green>synchronized</>';
66
            }
67
68 1
            $row[] = $description;
69 1
            $row[] = $recordsCounter->local($searchable);
70 1
            $row[] = $recordsCounter->remote($searchable);
71
72 1
            $rows[] = $row;
73 1
            $this->output->progressAdvance();
74
        }
75
76 1
        $this->output->progressFinish();
77 1
        $this->output->table(['Searchable', 'Index', 'Settings', 'Local records', 'Remote records'], $rows);
78 1
    }
79
}
80