CreateCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 14
c 1
b 0
f 1
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 22 2
1
<?php namespace Nord\Lumen\Elasticsearch\Console;
2
3
use Nord\Lumen\Elasticsearch\IndexNamePrefixer;
4
5
class CreateCommand extends AbstractCommand
6
{
7
8
    /**
9
     * The name and signature of the console command.
10
     *
11
     * @var string
12
     */
13
    protected $signature = 'elastic:index:create {config : Configuration file}';
14
15
    /**
16
     * The console command description.
17
     *
18
     * @var string
19
     */
20
    protected $description = 'Creates an Elasticsearch index from a configuration file.';
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function handle()
26
    {
27
        $config = (string)$this->argument('config');
28
29
        $filePath = realpath($config);
30
31
        if (!file_exists($filePath)) {
32
            $this->error(sprintf("Configuration file '%s' does not exist.", $config));
33
34
            return 1;
35
        }
36
37
        $params = require($filePath);
38
        $params = IndexNamePrefixer::getPrefixedIndexParameters($params);
39
40
        $this->info(sprintf("Creating index '%s' ...", $params['index']));
41
42
        $this->elasticsearchService->indices()->create($params);
43
44
        $this->info(sprintf("Index '%s' created.", $params['index']));
45
46
        return 0;
47
    }
48
}
49