Completed
Pull Request — master (#57)
by jean-marie
26:09
created

Attribute   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 5 1
B convertFields() 0 20 6
1
<?php
2
3
namespace Pim\Bundle\ExcelConnectorBundle\ArrayConverter\Flat;
4
5
use Pim\Bundle\ExcelConnectorBundle\Mapper\AttributeTypeMapperInterface;
6
use Pim\Component\Connector\ArrayConverter\FlatToStandard\Attribute as PimAttributeConverter;
7
8
/**
9
 * Convert flat format to standard format for attribute
10
 *
11
 * @author    JM Leroux <[email protected]>
12
 * @copyright 2016 Akeneo SAS (http://www.akeneo.com)
13
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
class Attribute extends PimAttributeConverter
16
{
17
    /** @var AttributeTypeMapperInterface */
18
    protected $attributeTypesMapper;
19
20
    public function convert(array $item, array $options = [])
21
    {
22
        $this->attributeTypesMapper = $options['attribute_types_mapper'];
23
        return parent::convert($item, $options);
24
    }
25
26
    protected function convertFields($field, $booleanFields, $data, $convertedItem)
27
    {
28
        if (empty($field) || 'use_as_label' === $field) {
29
            return $convertedItem;
30
        }
31
        if (empty($data)) {
32
            return $convertedItem;
33
        }
34
35
        $convertedItem = parent::convertFields($field, $booleanFields, $data, $convertedItem);
36
37
        if ('type' === $field) {
38
            $pimType = $this->attributeTypesMapper->getMappedValue($data);
39
            if (null !== $pimType) {
40
                $convertedItem['attribute_type'] = $pimType;
41
            }
42
        }
43
44
        return $convertedItem;
45
    }
46
}
47