Code Duplication    Length = 33-33 lines in 3 locations

src/Lodash/Elasticsearch/ElasticsearchManager.php 3 locations

@@ 122-154 (lines=33) @@
119
    /**
120
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException
121
     */
122
    public function addDocumentsToIndex(string $index_name, string $type_name, array $items)
123
    {
124
        if (! $this->isEnabled()) {
125
            return;
126
        }
127
128
        $params = [
129
            'body' => [],
130
        ];
131
132
        if (! empty($this->timeout)) {
133
            $params['client'] = [
134
                'timeout' => $this->timeout,
135
            ];
136
        }
137
138
        foreach ($items as $id => $item) {
139
            $params['body'][] = [
140
                'create' => [
141
                    '_index' => $index_name,
142
                    '_type'  => $type_name,
143
                    '_id'    => $id,
144
                ],
145
            ];
146
147
            $params['body'][] = $item;
148
        }
149
150
        $responses = $this->client->bulk($params);
151
        if ($responses['errors'] === true) {
152
            $this->handleBulkError($responses, 'Error occurred during bulk create');
153
        }
154
    }
155
156
    /**
157
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException
@@ 159-191 (lines=33) @@
156
    /**
157
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException
158
     */
159
    public function updateDocumentsInIndex(string $index_name, string $type_name, array $items)
160
    {
161
        if (! $this->isEnabled()) {
162
            return;
163
        }
164
165
        $params = [
166
            'body' => [],
167
        ];
168
169
        if (! empty($this->timeout)) {
170
            $params['client'] = [
171
                'timeout' => $this->timeout,
172
            ];
173
        }
174
175
        foreach ($items as $id => $item) {
176
            $params['body'][] = [
177
                'update' => [
178
                    '_index' => $index_name,
179
                    '_type'  => $type_name,
180
                    '_id'    => $id,
181
                ],
182
            ];
183
184
            $params['body'][] = ['doc' => $item];
185
        }
186
187
        $responses = $this->client->bulk($params);
188
        if ($responses['errors'] === true) {
189
            $this->handleBulkError($responses, 'Error occurred during bulk update');
190
        }
191
    }
192
193
    /**
194
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException
@@ 196-228 (lines=33) @@
193
    /**
194
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException
195
     */
196
    public function addOrUpdateDocumentsInIndex(string $index_name, string $type_name, array $items)
197
    {
198
        if (! $this->isEnabled()) {
199
            return;
200
        }
201
202
        $params = [
203
            'body' => [],
204
        ];
205
206
        if (! empty($this->timeout)) {
207
            $params['client'] = [
208
                'timeout' => $this->timeout,
209
            ];
210
        }
211
212
        foreach ($items as $id => $item) {
213
            $params['body'][] = [
214
                'index' => [
215
                    '_index' => $index_name,
216
                    '_type'  => $type_name,
217
                    '_id'    => $id,
218
                ],
219
            ];
220
221
            $params['body'][] = $item;
222
        }
223
224
        $responses = $this->client->bulk($params);
225
        if ($responses['errors'] === true) {
226
            $this->handleBulkError($responses, 'Error occurred during bulk index');
227
        }
228
    }
229
230
    /**
231
     * @throws \Longman\LaravelLodash\Elasticsearch\ElasticsearchException