Passed
Pull Request — master (#87)
by
unknown
05:18
created

VariantImagePathResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 9
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 Sylius\Component\Core\Model\ProductVariantInterface;
14
15
final class VariantImagePathResolver implements VariantImagePathResolverInterface
16
{
17
    public function resolve(ProductVariantInterface $variant, string $baseUrl)
18
    {
19
        if ( false === $variant->getProduct()->getImages()->first()) {
0 ignored issues
show
Bug introduced by
The method getImages() does not exist on Sylius\Component\Product\Model\ProductInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Product\Model\Product. Are you sure you never get one of those? ( Ignorable by Annotation )

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

19
        if ( false === $variant->getProduct()->/** @scrutinizer ignore-call */ getImages()->first()) {
Loading history...
20
            return 'http://placehold.it/150x150';
21
        }
22
23
        $imagePath = $variant->getProduct()->getImages()->first()->getPath();
24
25
        return $baseUrl.'/media/image/'.$imagePath;
26
    }
27
}