Code Duplication    Length = 86-87 lines in 2 locations

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

Core/Executor/LocationManager.php 1 location

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