Code Duplication    Length = 39-39 lines in 2 locations

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

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

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

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