Completed
Push — master ( 9800c9...34c9ed )
by Kamil
18:26
created

AttributeFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createTyped() 0 8 1
A createNew() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Attribute\Factory;
13
14
use Sylius\Component\Product\Model\Attribute;
15
use Sylius\Component\Registry\ServiceRegistryInterface;
16
use Sylius\Component\Resource\Factory\FactoryInterface;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 */
21
class AttributeFactory implements AttributeFactoryInterface
22
{
23
    /**
24
     * @var FactoryInterface
25
     */
26
    private $factory;
27
28
    /**
29
     * @var ServiceRegistryInterface
30
     */
31
    private $attributeTypesRegistry;
32
33
    /**
34
     * @param FactoryInterface $factory
35
     * @param ServiceRegistryInterface $attributeTypesRegistry
36
     */
37
    public function __construct(FactoryInterface $factory, ServiceRegistryInterface $attributeTypesRegistry)
38
    {
39
        $this->factory = $factory;
40
        $this->attributeTypesRegistry = $attributeTypesRegistry;
41
    }
42
43
    /**
44
     * @param string $type
45
     *
46
     * @return Attribute
47
     */
48
    public function createTyped($type)
49
    {
50
        $attribute = $this->factory->createNew();
51
        $attribute->setType($type);
52
        $attribute->setStorageType($this->attributeTypesRegistry->get($type)->getStorageType());
53
54
        return $attribute;
55
    }
56
57
    /**
58
     * @return Attribute
59
     */
60
    public function createNew()
61
    {
62
        $attribute = $this->factory->createNew();
63
        $attribute->setStorageType($this->attributeTypesRegistry->get($attribute->getType())->getStorageType());
64
65
        return $attribute;
66
    }
67
}
68