Passed
Push — trunk ( 36db4a...0fa3f8 )
by Christian
16:05 queued 14s
created

MediaLoadedSubscriber::addUrls()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 4
nop 1
dl 0
loc 12
rs 9.6111
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Media\Subscriber;
4
5
use Shopware\Core\Content\Media\Aggregate\MediaThumbnail\MediaThumbnailCollection;
6
use Shopware\Core\Content\Media\MediaEntity;
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Content\Media\MediaEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
8
use Shopware\Core\Framework\Log\Package;
9
10
#[Package('buyers-experience')]
11
class MediaLoadedSubscriber
12
{
13
    public function unserialize(EntityLoadedEvent $event): void
14
    {
15
        /** @var MediaEntity $media */
16
        foreach ($event->getEntities() as $media) {
17
            if ($media->getMediaTypeRaw()) {
18
                $media->setMediaType(unserialize($media->getMediaTypeRaw()));
19
            }
20
21
            if ($media->getThumbnails() !== null) {
22
                continue;
23
            }
24
25
            $thumbnails = match (true) {
26
                $media->getThumbnailsRo() !== null => unserialize($media->getThumbnailsRo()),
27
                default => new MediaThumbnailCollection(),
28
            };
29
30
            $media->setThumbnails($thumbnails);
31
        }
32
    }
33
}
34