Code Duplication    Length = 39-39 lines in 2 locations

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

@@ 171-209 (lines=39) @@
168
     * This is based on code found in the culturefeed theme.
169
     * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284
170
     */
171
    private function importPicture($detail, $jsonLD)
172
    {
173
        $mainPicture = null;
174
175
        // first check if there is a media file that is main and has the PHOTO media type
176
        $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO);
177
        foreach ($photos as $photo) {
178
            if ($photo->isMain()) {
179
                $mainPicture = $photo;
180
            }
181
        }
182
183
        // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO
184
        if (empty($mainPicture)) {
185
            $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
186
            foreach ($images as $image) {
187
                if ($image->isMain()) {
188
                    $mainPicture = $image;
189
                }
190
            }
191
        }
192
193
        // if there is no explicit main image we just use the oldest picture of any type
194
        if (empty($mainPicture)) {
195
            $pictures = $detail->getMedia()->byMediaTypes(
196
                [
197
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO,
198
                    CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB
199
                ]
200
            );
201
202
            $pictures->rewind();
203
            $mainPicture = count($pictures) > 0 ? $pictures->current() : null;
204
        }
205
206
        if ($mainPicture) {
207
            $jsonLD->image = $mainPicture->getHLink();
208
        }
209
    }
210
}
211

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

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