Code Duplication    Length = 86-87 lines in 2 locations

Core/Executor/LocationManager.php 1 location

@@ 273-358 (lines=86) @@
270
     * @throws \InvalidArgumentException When trying to assign a reference to an unsupported attribute
271
     * @return array key: the reference names, values: the reference values
272
     */
273
    protected function getReferencesValues($location, array $references, $step)
274
    {
275
        $refs = array();
276
277
        foreach ($references as $reference) {
278
            switch ($reference['attribute']) {
279
                case 'location_id':
280
                case 'id':
281
                    $value = $location->id;
282
                    break;
283
                case 'remote_id':
284
                case 'location_remote_id':
285
                    $value = $location->remoteId;
286
                    break;
287
                case 'always_available':
288
                    $value = $location->contentInfo->alwaysAvailable;
289
                    break;
290
                case 'content_id':
291
                    $value = $location->contentId;
292
                    break;
293
                case 'content_type_id':
294
                    $value = $location->contentInfo->contentTypeId;
295
                    break;
296
                case 'content_type_identifier':
297
                    $contentTypeService = $this->repository->getContentTypeService();
298
                    $value = $contentTypeService->loadContentType($location->contentInfo->contentTypeId)->identifier;
299
                    break;
300
                case 'current_version':
301
                case 'current_version_no':
302
                    $value = $location->contentInfo->currentVersionNo;
303
                    break;
304
                case 'depth':
305
                    $value = $location->depth;
306
                    break;
307
                case 'is_hidden':
308
                    $value = $location->hidden;
309
                    break;
310
                case 'main_location_id':
311
                    $value = $location->contentInfo->mainLocationId;
312
                    break;
313
                case 'main_language_code':
314
                    $value = $location->contentInfo->mainLanguageCode;
315
                    break;
316
                case 'modification_date':
317
                    $value = $location->contentInfo->modificationDate->getTimestamp();
318
                    break;
319
                case 'name':
320
                    $value = $location->contentInfo->name;
321
                    break;
322
                case 'owner_id':
323
                    $value = $location->contentInfo->ownerId;
324
                    break;
325
                case 'parent_location_id':
326
                    $value = $location->parentLocationId;
327
                    break;
328
                case 'path':
329
                    $value = $location->pathString;
330
                    break;
331
                case 'priority':
332
                    $value = $location->priority;
333
                    break;
334
                case 'publication_date':
335
                    $value = $location->contentInfo->publishedDate->getTimestamp();
336
                    break;
337
                case 'section_id':
338
                    $value = $location->contentInfo->sectionId;
339
                    break;
340
                case 'section_identifier':
341
                    $sectionService = $this->repository->getSectionService();
342
                    $value = $sectionService->loadSection($location->contentInfo->sectionId)->identifier;
343
                    break;
344
                case 'sort_field':
345
                    $value = $this->sortConverter->sortField2Hash($location->sortField);
346
                    break;
347
                case 'sort_order':
348
                    $value = $this->sortConverter->sortOrder2Hash($location->sortOrder);
349
                    break;
350
                default:
351
                    throw new \InvalidArgumentException('Location Manager does not support setting references for attribute ' . $reference['attribute']);
352
            }
353
354
            $refs[$reference['identifier']] = $value;
355
        }
356
357
        return $refs;
358
    }
359
360
    /**
361
     * @param int|string|array $locationKey

Core/Executor/TrashManager.php 1 location

@@ 114-200 (lines=87) @@
111
     * @throws \InvalidArgumentException When trying to assign a reference to an unsupported attribute
112
     * @return array key: the reference names, values: the reference values
113
     */
114
    protected function getReferencesValues($item, array $references, $step)
115
    {
116
        $refs = array();
117
118
        foreach ($references as $reference) {
119
            switch ($reference['attribute']) {
120
                // a trashed item extends a location, so in theory everything 'location' here should work
121
                case 'location_id':
122
                case 'id':
123
                    $value = $item->id;
124
                    break;
125
                case 'remote_id':
126
                case 'location_remote_id':
127
                    $value = $item->remoteId;
128
                    break;
129
                case 'always_available':
130
                    $value = $item->contentInfo->alwaysAvailable;
131
                    break;
132
                case 'content_id':
133
                    $value = $item->contentId;
134
                    break;
135
                case 'content_type_id':
136
                    $value = $item->contentInfo->contentTypeId;
137
                    break;
138
                case 'content_type_identifier':
139
                    $contentTypeService = $this->repository->getContentTypeService();
140
                    $value = $contentTypeService->loadContentType($item->contentInfo->contentTypeId)->identifier;
141
                    break;
142
                case 'current_version':
143
                case 'current_version_no':
144
                    $value = $item->contentInfo->currentVersionNo;
145
                    break;
146
                case 'depth':
147
                    $value = $item->depth;
148
                    break;
149
                case 'is_hidden':
150
                    $value = $item->hidden;
151
                    break;
152
                case 'main_location_id':
153
                    $value = $item->contentInfo->mainLocationId;
154
                    break;
155
                case 'main_language_code':
156
                    $value = $item->contentInfo->mainLanguageCode;
157
                    break;
158
                case 'modification_date':
159
                    $value = $item->contentInfo->modificationDate->getTimestamp();
160
                    break;
161
                case 'name':
162
                    $value = $item->contentInfo->name;
163
                    break;
164
                case 'owner_id':
165
                    $value = $item->contentInfo->ownerId;
166
                    break;
167
                case 'parent_location_id':
168
                    $value = $item->parentLocationId;
169
                    break;
170
                case 'path':
171
                    $value = $item->pathString;
172
                    break;
173
                case 'priority':
174
                    $value = $item->priority;
175
                    break;
176
                case 'publication_date':
177
                    $value = $item->contentInfo->publishedDate->getTimestamp();
178
                    break;
179
                case 'section_id':
180
                    $value = $item->contentInfo->sectionId;
181
                    break;
182
                case 'section_identifier':
183
                    $sectionService = $this->repository->getSectionService();
184
                    $value = $sectionService->loadSection($item->contentInfo->sectionId)->identifier;
185
                    break;
186
                case 'sort_field':
187
                    $value = $this->sortConverter->sortField2Hash($item->sortField);
188
                    break;
189
                case 'sort_order':
190
                    $value = $this->sortConverter->sortOrder2Hash($item->sortOrder);
191
                    break;
192
                default:
193
                    throw new \InvalidArgumentException('Trash Manager does not support setting references for attribute ' . $reference['attribute']);
194
            }
195
196
            $refs[$reference['identifier']] = $value;
197
        }
198
199
        return $refs;
200
    }
201
}
202