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

ModelCreator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
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\Services\Generator;
12
13
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface;
14
use BitBag\SyliusWishlistPlugin\Model\Factory\VariantPdfModelFactoryInterface;
15
use BitBag\SyliusWishlistPlugin\Model\VariantPdfModelInterface;
16
use BitBag\SyliusWishlistPlugin\Resolver\VariantImageToDataUriResolverInterface;
17
use Sylius\Component\Core\Model\ProductVariant;
18
use Symfony\Component\HttpFoundation\Request;
19
20
final class ModelCreator implements ModelCreatorInterface
21
{
22
    private VariantImageToDataUriResolverInterface $variantImageToDataUriResolver;
23
24
    private VariantPdfModelFactoryInterface $variantPdfModelFactory;
25
26
    public function __construct(
27
        VariantImageToDataUriResolverInterface $variantImageToDataUriResolver,
28
        VariantPdfModelFactoryInterface $variantPdfModelFactory
29
    ) {
30
        $this->variantImageToDataUriResolver = $variantImageToDataUriResolver;
31
        $this->variantPdfModelFactory = $variantPdfModelFactory;
32
    }
33
34
    public function createWishlistItemToPdf(
35
        WishlistItemInterface $wishlistProduct,
36
        Request $request,
37
        ProductVariant $variant
38
    ): VariantPdfModelInterface
39
    {
40
        $cartItem = $wishlistProduct->getCartItem()->getCartItem();
41
        $quantity = $cartItem->getQuantity();
42
        $baseUrl = $request->getSchemeAndHttpHost();
43
        $urlToImage = $this->variantImageToDataUriResolver->resolve($variant, $baseUrl);
44
        $actualVariant = $cartItem->getVariant()->getCode();
0 ignored issues
show
Bug introduced by
The method getVariant() does not exist on Sylius\Component\Order\Model\OrderItemInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sylius\Component\Order\Model\OrderItem. 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

44
        $actualVariant = $cartItem->/** @scrutinizer ignore-call */ getVariant()->getCode();
Loading history...
45
46
        return $this->variantPdfModelFactory->createWithVariantAndImagePath(
47
            $variant,
48
            $urlToImage,
49
            $quantity,
50
            $actualVariant
51
        );
52
    }
53
}
54