Code Duplication    Length = 39-39 lines in 2 locations

src/Place/ReadModel/JSONLD/CdbXMLImporter.php 1 location

@@ 193-231 (lines=39) @@
190
     * This is based on code found in the culturefeed theme.
191
     * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284
192
     */
193
    private function importPicture($detail, $jsonLD)
194
    {
195
        $mainPicture = null;
196
197
        // first check if there is a media file that is main and has the PHOTO media type
198
        $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO);
199
        foreach ($photos as $photo) {
200
            if ($photo->isMain()) {
201
                $mainPicture = $photo;
202
            }
203
        }
204
205
        // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO
206
        if (empty($mainPicture)) {
207
            $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
208
            foreach ($images as $image) {
209
                if ($image->isMain()) {
210
                    $mainPicture = $image;
211
                }
212
            }
213
        }
214
215
        // if there is no explicit main image we just use the oldest picture of any type
216
        if (empty($mainPicture)) {
217
            $pictures = $detail->getMedia()->byMediaTypes(
218
                [
219
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO,
220
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB
221
                ]
222
            );
223
224
            $pictures->rewind();
225
            $mainPicture = count($pictures) > 0 ? $pictures->current() : null;
226
        }
227
228
        if ($mainPicture) {
229
            $jsonLD->image = $mainPicture->getHLink();
230
        }
231
    }
232
}
233

src/Event/ReadModel/JSONLD/CdbXMLImporter.php 1 location

@@ 243-281 (lines=39) @@
240
     * This is based on code found in the culturefeed theme.
241
     * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284
242
     */
243
    private function importPicture($detail, $jsonLD)
244
    {
245
        $mainPicture = null;
246
247
        // first check if there is a media file that is main and has the PHOTO media type
248
        $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO);
249
        foreach ($photos as $photo) {
250
            if ($photo->isMain()) {
251
                $mainPicture = $photo;
252
            }
253
        }
254
255
        // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO
256
        if (empty($mainPicture)) {
257
            $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
258
            foreach ($images as $image) {
259
                if ($image->isMain()) {
260
                    $mainPicture = $image;
261
                }
262
            }
263
        }
264
265
        // if there is no explicit main image we just use the oldest picture of any type
266
        if (empty($mainPicture)) {
267
            $pictures = $detail->getMedia()->byMediaTypes(
268
                [
269
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO,
270
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB
271
                ]
272
            );
273
274
            $pictures->rewind();
275
            $mainPicture = count($pictures) > 0 ? $pictures->current() : null;
276
        }
277
278
        if ($mainPicture) {
279
            $jsonLD->image = $mainPicture->getHLink();
280
        }
281
    }
282
283
    /**
284
     * @param \CultureFeed_Cdb_Item_Event $event