Code Duplication    Length = 39-39 lines in 2 locations

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

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

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