Completed
Pull Request — master (#169)
by Łukasz
03:14
created

DetailedProductViewFactory::createWithVariants()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.7972
cc 4
eloc 10
nc 6
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\ChannelInterface;
8
use Sylius\Component\Core\Model\ProductImageInterface;
9
use Sylius\Component\Core\Model\ProductInterface;
10
use Sylius\Component\Core\Model\ProductVariantInterface;
11
use Sylius\Component\Product\Model\ProductAssociationInterface;
12
use Sylius\ShopApiPlugin\Generator\ProductBreadcrumbGeneratorInterface;
13
use Sylius\ShopApiPlugin\View\ProductVariantView;
14
use Sylius\ShopApiPlugin\View\ProductView;
15
16
final class DetailedProductViewFactory implements ProductViewFactoryInterface
17
{
18
    /**
19
     * @var ProductViewFactoryInterface
20
     */
21
    private $productViewFactory;
22
23
    /**
24
     * @var ProductBreadcrumbGeneratorInterface
25
     */
26
    private $breadcrumbGenerator;
27
28
    /**
29
     * @param ProductViewFactoryInterface $productViewFactory
30
     * @param ProductBreadcrumbGeneratorInterface $breadcrumbGenerator
31
     */
32
    public function __construct(
33
        ProductViewFactoryInterface $productViewFactory,
34
        ProductBreadcrumbGeneratorInterface $breadcrumbGenerator
35
    ) {
36
        $this->productViewFactory = $productViewFactory;
37
        $this->breadcrumbGenerator = $breadcrumbGenerator;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function create(ProductInterface $product, ChannelInterface $channel, string $locale): ProductView
44
    {
45
        $productView = $this->productViewFactory->create($product, $channel, $locale);
46
        $productView->breadcrumb = $this->breadcrumbGenerator->generate($product, $locale);
47
48
        return $productView;
49
    }
50
}
51