LimitedProductAttributeValuesViewFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Product\Model\ProductAttributeValueInterface;
8
9
final class LimitedProductAttributeValuesViewFactory implements ProductAttributeValuesViewFactoryInterface
10
{
11
    /** @var ProductAttributeValueViewFactoryInterface */
12
    private $productAttributeValueViewFactory;
13
14
    /** @var string[] */
15
    private $allowedAttributesCodes;
16
17
    public function __construct(ProductAttributeValueViewFactoryInterface $productAttributeValueViewFactory, array $allowedAttributesCodes)
18
    {
19
        $this->productAttributeValueViewFactory = $productAttributeValueViewFactory;
20
        $this->allowedAttributesCodes = $allowedAttributesCodes;
21
    }
22
23
    public function create(array $attributeValues, string $locale): array
24
    {
25
        $attributeValuesView = [];
26
27
        /** @var ProductAttributeValueInterface $attributeValue */
28
        foreach ($attributeValues as $attributeValue) {
29
            if (!in_array($attributeValue->getCode(), $this->allowedAttributesCodes, true)) {
30
                continue;
31
            }
32
33
            $attributeValuesView[] = $this->productAttributeValueViewFactory->create($attributeValue, $locale);
34
        }
35
36
        return $attributeValuesView;
37
    }
38
}
39