ProductAttributeValueViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Product\Model\ProductAttributeTranslationInterface;
8
use Sylius\Component\Product\Model\ProductAttributeValueInterface;
9
use Sylius\ShopApiPlugin\View\ProductAttributeValueView;
10
11
final class ProductAttributeValueViewFactory implements ProductAttributeValueViewFactoryInterface
12
{
13
    /** @var string */
14
    private $productAttributeValueViewClass;
15
16
    public function __construct(string $productAttributeValueViewClass)
17
    {
18
        $this->productAttributeValueViewClass = $productAttributeValueViewClass;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function create(ProductAttributeValueInterface $productAttributeValue, string $locale): ProductAttributeValueView
25
    {
26
        /** @var ProductAttributeValueView $productAttributeValueView */
27
        $productAttributeValueView = new $this->productAttributeValueViewClass();
28
29
        $productAttributeValueView->code = $productAttributeValue->getCode();
30
        $productAttributeValueView->value = $productAttributeValue->getValue();
31
32
        $productAttribute = $productAttributeValue->getAttribute();
33
34
        /** @var ProductAttributeTranslationInterface $productAttributeTranslation */
35
        $productAttributeTranslation = $productAttribute->getTranslation($locale);
36
        $productAttributeValueView->name = $productAttributeTranslation->getName();
37
38
        return $productAttributeValueView;
39
    }
40
}
41