NntmuxCreateESIndexes::handle()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 97
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 97
rs 8.8509
c 0
b 0
f 0
cc 3
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Console\Commands;
4
5
use Elasticsearch;
6
use Illuminate\Console\Command;
7
8
class NntmuxCreateESIndexes extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'nntmux:create-es-indexes';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create ElasticSearch Indexes';
23
24
    /**
25
     * Execute the console command.
26
     */
27
    public function handle(): void
28
    {
29
        if (Elasticsearch::indices()->exists(['index' => 'releases'])) {
30
            Elasticsearch::indices()->delete(['index' => 'releases']);
31
        }
32
        $releases_index = [
33
            'index' => 'releases',
34
            'body' => [
35
                'settings' => [
36
                    'number_of_shards' => 2,
37
                    'number_of_replicas' => 0,
38
                ],
39
                'mappings' => [
40
                    'properties' => [
41
                        'id' => [
42
                            'type' => 'long',
43
                            'index' => false,
44
                        ],
45
                        'name' => ['type' => 'text'],
46
                        'searchname' => [
47
                            'type' => 'text',
48
                            'fields' => [
49
                                'sort' => [
50
                                    'type' => 'keyword',
51
                                ],
52
                            ],
53
                        ],
54
                        'plainsearchname' => [
55
                            'type' => 'text',
56
                            'fields' => [
57
                                'sort' => [
58
                                    'type' => 'keyword',
59
                                ],
60
                            ],
61
                        ],
62
                        'categories_id' => [
63
                            'type' => 'text',
64
                        ],
65
                        'fromname' => [
66
                            'type' => 'text',
67
                        ],
68
                        'filename' => [
69
                            'type' => 'text',
70
                        ],
71
                        'add_date' => [
72
                            'type' => 'date',
73
                            'format' => 'yyyy-MM-dd HH:mm:ss',
74
                        ],
75
                        'post_date' => [
76
                            'type' => 'date',
77
                            'format' => 'yyyy-MM-dd HH:mm:ss',
78
                        ],
79
                    ],
80
                ],
81
            ],
82
        ];
83
84
        $response = Elasticsearch::indices()->create($releases_index);
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
85
86
        $this->info('Index releases created successfully');
87
        if (Elasticsearch::indices()->exists(['index' => 'predb'])) {
88
            Elasticsearch::indices()->delete(['index' => 'predb']);
89
        }
90
        $predb_index = [
91
            'index' => 'predb',
92
            'body' => [
93
                'settings' => [
94
                    'number_of_shards' => 2,
95
                    'number_of_replicas' => 0,
96
                ],
97
                'mappings' => [
98
                    'properties' => [
99
                        'id' => [
100
                            'type' => 'long',
101
                            'index' => false,
102
                        ],
103
                        'title' => [
104
                            'type' => 'text',
105
                            'fields' => [
106
                                'sort' => [
107
                                    'type' => 'keyword',
108
                                ],
109
                            ],
110
                        ],
111
                        'filename' => ['type' => 'text'],
112
                        'source' => ['type' => 'text'],
113
                    ],
114
                ],
115
            ],
116
117
        ];
118
119
        $response = Elasticsearch::indices()->create($predb_index);
120
121
        $this->info('Index predb created successfully');
122
123
        $this->info('All done! ElasticSearch indexes are created now.');
124
    }
125
}
126