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

@@ 226-264 (lines=39) @@
223
     * This is based on code found in the culturefeed theme.
224
     * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284
225
     */
226
    private function importPicture($detail, $jsonLD)
227
    {
228
        $mainPicture = null;
229
230
        // first check if there is a media file that is main and has the PHOTO media type
231
        $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO);
232
        foreach ($photos as $photo) {
233
            if ($photo->isMain()) {
234
                $mainPicture = $photo;
235
            }
236
        }
237
238
        // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO
239
        if (empty($mainPicture)) {
240
            $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
241
            foreach ($images as $image) {
242
                if ($image->isMain()) {
243
                    $mainPicture = $image;
244
                }
245
            }
246
        }
247
248
        // if there is no explicit main image we just use the oldest picture of any type
249
        if (empty($mainPicture)) {
250
            $pictures = $detail->getMedia()->byMediaTypes(
251
                [
252
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO,
253
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB
254
                ]
255
            );
256
257
            $pictures->rewind();
258
            $mainPicture = count($pictures) > 0 ? $pictures->current() : null;
259
        }
260
261
        if ($mainPicture) {
262
            $jsonLD->image = $mainPicture->getHLink();
263
        }
264
    }
265
266
    /**
267
     * @param \CultureFeed_Cdb_Item_Event $event