Passed
Push — master ( a4037f...e3e9e9 )
by Christopher
01:15
created

src/Console/Commands/Version/Overview.php (1 issue)

Labels
Severity
1
<?php
2
namespace Triadev\Es\Console\Commands\Version;
3
4
use Triadev\Es\Contract\ElasticsearchAliasContract;
5
use Triadev\Es\Contract\ElasticsearchIndexContract;
6
use Illuminate\Console\Command;
7
8
class Overview extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'triadev:es:version:overview
16
                            {index : Index}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Get an overview of the version of an index.';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @param ElasticsearchIndexContract $elasticsearchIndex
29
     * @param ElasticsearchAliasContract $elasticsearchAlias
30
     */
31 1
    public function handle(
32
        ElasticsearchIndexContract $elasticsearchIndex,
33
        ElasticsearchAliasContract $elasticsearchAlias
34
    ) {
35 1
        $indices = $elasticsearchIndex->getVersionedIndices($this->argument('index'));
0 ignored issues
show
It seems like $this->argument('index') can also be of type null and string[]; however, parameter $index of Triadev\Es\Contract\Elas...::getVersionedIndices() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

35
        $indices = $elasticsearchIndex->getVersionedIndices(/** @scrutinizer ignore-type */ $this->argument('index'));
Loading history...
36
37 1
        $headers = ['Name', 'Version', 'Active'];
38
39 1
        $rows = [];
40
41 1
        foreach ($indices as $index) {
42 1
            if (preg_match('/(?<name>[a-z]+)_(?<version>[0-9]+.[0-9]+.[0-9]+)/', $index, $matches)) {
43 1
                $rows[$matches['version']] = [
44 1
                    $matches['name'],
45 1
                    $matches['version'],
46 1
                    $elasticsearchAlias->existAlias(
47 1
                        [$matches['name']],
48 1
                        [$matches['name']],
49 1
                        $matches['version']
50 1
                    ) ? 'true' : 'false'
51
                ];
52
            }
53
        }
54
55 1
        $this->table($headers, $rows);
56 1
    }
57
}
58