Conditions | 3 |
Paths | 4 |
Total Lines | 97 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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); |
||
|
|||
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 | } |
||
126 |