MediaUploadListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\EventListener;
12
13
use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
14
use BitBag\SyliusCmsPlugin\Resolver\MediaProviderResolverInterface;
15
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
16
use Webmozart\Assert\Assert;
17
18
final class MediaUploadListener
19
{
20
    /** @var MediaProviderResolverInterface */
21
    private $mediaProviderResolver;
22
23
    public function __construct(MediaProviderResolverInterface $mediaProviderResolver)
24
    {
25
        $this->mediaProviderResolver = $mediaProviderResolver;
26
    }
27
28
    public function uploadMedia(ResourceControllerEvent $event): void
29
    {
30
        /** @var MediaInterface|null $media */
31
        $media = $event->getSubject();
32
33
        Assert::isInstanceOf($media, MediaInterface::class);
34
35
        $this->mediaProviderResolver->resolveProvider($media)->upload($media);
0 ignored issues
show
Bug introduced by
It seems like $media can also be of type null; however, parameter $media of BitBag\SyliusCmsPlugin\R...face::resolveProvider() does only seem to accept BitBag\SyliusCmsPlugin\Entity\MediaInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $this->mediaProviderResolver->resolveProvider(/** @scrutinizer ignore-type */ $media)->upload($media);
Loading history...
Bug introduced by
It seems like $media can also be of type null; however, parameter $media of BitBag\SyliusCmsPlugin\M...iderInterface::upload() does only seem to accept BitBag\SyliusCmsPlugin\Entity\MediaInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $this->mediaProviderResolver->resolveProvider($media)->upload(/** @scrutinizer ignore-type */ $media);
Loading history...
36
    }
37
}
38