Passed
Push — master ( 6daa1b...44aa55 )
by Przemysław eRIZ
04:09
created

GenerateDataUriForImageResolver::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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\SyliusWishlistPlugin\Resolver;
12
13
use Liip\ImagineBundle\Service\FilterService;
14
use Sylius\Component\Core\Model\ProductImageInterface;
15
use Symfony\Component\Asset\PackageInterface;
16
17
final class GenerateDataUriForImageResolver implements GenerateDataUriForImageResolverInterface
18
{
19
    private PackageInterface $package;
20
21
    private FilterService $filterService;
22
23
    private string $imageFilterName;
24
25
    public function __construct(
26
        PackageInterface $package,
27
        FilterService $filterService,
28
        string $imageFilterName
29
    ) {
30
        $this->package = $package;
31
        $this->filterService = $filterService;
32
        $this->imageFilterName = $imageFilterName;
33
    }
34
35
    public function resolve(ProductImageInterface $image): string
36
    {
37
        $pathToReadFile = $this->package->getUrl($image->getPath());
0 ignored issues
show
Bug introduced by
It seems like $image->getPath() can also be of type null; however, parameter $path of Symfony\Component\Asset\PackageInterface::getUrl() 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

37
        $pathToReadFile = $this->package->getUrl(/** @scrutinizer ignore-type */ $image->getPath());
Loading history...
38
        $targetUrl = $this->filterService->getUrlOfFilteredImage($pathToReadFile, $this->imageFilterName);
39
        $data = file_get_contents($targetUrl);
40
        $type = pathinfo($image->getPath(), \PATHINFO_EXTENSION);
0 ignored issues
show
Bug introduced by
It seems like $image->getPath() can also be of type null; however, parameter $path of pathinfo() 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

40
        $type = pathinfo(/** @scrutinizer ignore-type */ $image->getPath(), \PATHINFO_EXTENSION);
Loading history...
41
42
        return 'data:image/' . $type . ';base64,' . base64_encode($data);
43
    }
44
}
45