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

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