ProductVariantsToConfigurableChildrenTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A transform() 0 15 2
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.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Sylius\Transformer\SyliusProduct;
14
15
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ConfigurableChildren;
16
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ConfigurableChildren\Child;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Core\Model\ProductVariantInterface;
19
20
final class ProductVariantsToConfigurableChildrenTransformer implements ProductVariantsToConfigurableChildrenTransformerInterface
21
{
22
    /** @var ProductVariantPricesTransformerInterface */
23
    private $productVariantPricesTransformer;
24
25
    /** @var ProductVariantOptionValuesToCustomAttributesTransformerInterface */
26
    private $productVariantOptionValuesToCustomAttributesTransformer;
27
28
    public function __construct(
29
        ProductVariantPricesTransformerInterface $productVariantPricesTransformer,
30
        ProductVariantOptionValuesToCustomAttributesTransformerInterface $productVariantOptionValuesToCustomAttributesTransformer
31
    ) {
32
        $this->productVariantPricesTransformer = $productVariantPricesTransformer;
33
        $this->productVariantOptionValuesToCustomAttributesTransformer = $productVariantOptionValuesToCustomAttributesTransformer;
34
    }
35
36
    /** @param Collection|ProductVariantInterface[] $syliusProductVariants */
37
    public function transform(Collection $syliusProductVariants): ConfigurableChildren
38
    {
39
        $configurableChildren = [];
40
41
        foreach ($syliusProductVariants as $productVariant) {
42
            $configurableChildren[] = new Child(
43
                $this->productVariantPricesTransformer->transform($productVariant),
44
                $productVariant->getName(),
45
                $productVariant->getCode(),
46
                $this->productVariantOptionValuesToCustomAttributesTransformer->transform($productVariant)
47
            );
48
        }
49
50
        return new ConfigurableChildren($configurableChildren);
51
    }
52
}
53