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

Create   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
wmc 2
eloc 21
dl 0
loc 49
ccs 13
cts 18
cp 0.7221
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 25 2
1
<?php
2
namespace Triadev\Es\Console\Commands\Alias;
3
4
use Triadev\Es\Contract\ElasticsearchAliasContract;
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Log;
7
8
class Create extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'triadev:es:alias:create
16
                            {index : Index}
17
                            {alias : Alias}
18
                            {version : Version}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Create an alias.';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @param ElasticsearchAliasContract $elasticsearchAlias
31
     */
32 2
    public function handle(ElasticsearchAliasContract $elasticsearchAlias)
33
    {
34 2
        $index = (string)$this->argument('index');
35 2
        $alias = (string)$this->argument('alias');
36 2
        $version = (string)$this->argument('version');
37
38 2
        Log::info("The alias is created.", [
39 2
            'index' => $index,
40 2
            'alias' => $alias,
41 2
            'version' => $version
42
        ]);
43
44
        try {
45 2
            $elasticsearchAlias->addAlias($index, $alias, $version);
46
47 2
            Log::info("The alias was created.", [
48 2
                'index' => $index,
49 2
                'alias' => $alias,
50 2
                'version' => $version
51
            ]);
52
        } catch (\Throwable $e) {
53
            Log::error($e->getMessage(), [
54
                'index' => $index,
55
                'alias' => $alias,
56
                'version' => $version
57
            ]);
58
        }
59 2
    }
60
}
61