MediaProviderResolver::resolveProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
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\Resolver;
12
13
use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
14
use BitBag\SyliusCmsPlugin\MediaProvider\ProviderInterface;
15
use Sylius\Component\Registry\ServiceRegistryInterface;
16
use Webmozart\Assert\Assert;
17
18
final class MediaProviderResolver implements MediaProviderResolverInterface
19
{
20
    /** @var ServiceRegistryInterface */
21
    private $providerRegistry;
22
23
    public function __construct(ServiceRegistryInterface $providerRegistry)
24
    {
25
        $this->providerRegistry = $providerRegistry;
26
    }
27
28
    public function resolveProvider(MediaInterface $media): ProviderInterface
29
    {
30
        Assert::notNull($media->getType());
31
        /** @var ProviderInterface $provider */
32
        $provider = $this->providerRegistry->get($media->getType());
0 ignored issues
show
Bug introduced by
It seems like $media->getType() can also be of type null; however, parameter $identifier of Sylius\Component\Registr...egistryInterface::get() does only seem to accept string, 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

32
        $provider = $this->providerRegistry->get(/** @scrutinizer ignore-type */ $media->getType());
Loading history...
33
34
        return $provider;
35
    }
36
}
37