Passed
Push — master ( 6740cb...eae932 )
by Damian
12:53
created

src/Resolver/MediaResourceResolver.php (1 issue)

Labels
Severity
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Resolver;
14
15
use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
16
use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface;
17
use Psr\Log\LoggerInterface;
18
use Sylius\Component\Channel\Context\ChannelContextInterface;
19
20
final class MediaResourceResolver implements MediaResourceResolverInterface
21
{
22
    /** @var MediaRepositoryInterface */
23
    private $mediaRepository;
24
25
    /** @var ChannelContextInterface */
26
    private $channelContext;
27
28
    /** @var LoggerInterface */
29
    private $logger;
30
31
    public function __construct(
32
        MediaRepositoryInterface $mediaRepository,
33
        ChannelContextInterface $channelContext,
34
        LoggerInterface $logger
35
    ) {
36
        $this->mediaRepository = $mediaRepository;
37
        $this->channelContext = $channelContext;
38
        $this->logger = $logger;
39
    }
40
41
    public function findOrLog(string $code): ?MediaInterface
42
    {
43
        $media = $this->mediaRepository->findOneEnabledByCode($code, $this->channelContext->getChannel()->getCode());
0 ignored issues
show
It seems like $this->channelContext->getChannel()->getCode() can also be of type null; however, parameter $localeCode of BitBag\SyliusCmsPlugin\R...:findOneEnabledByCode() 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

43
        $media = $this->mediaRepository->findOneEnabledByCode($code, /** @scrutinizer ignore-type */ $this->channelContext->getChannel()->getCode());
Loading history...
44
45
        if (false === $media instanceof MediaInterface) {
46
            $this->logger->warning(sprintf(
47
                'Media with "%s" code was not found in the database.',
48
                $code
49
            ));
50
51
            return null;
52
        }
53
54
        return $media;
55
    }
56
}
57