AttributeProcessor::normalizeAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Processor;
4
5
use Akeneo\Bundle\BatchBundle\Item\InvalidItemException;
6
use Akeneo\Bundle\BatchBundle\Entity\StepExecution;
7
use Akeneo\Bundle\BatchBundle\Item\ItemProcessorInterface;
8
use Pim\Bundle\CatalogBundle\Entity\Attribute;
9
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\Exception\NormalizeException;
10
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\AttributeNormalizer;
11
use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep;
12
13 View Code Duplication
class AttributeProcessor extends DrupalItemStep implements ItemProcessorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @var AttributeNormalizer $attributeNormalizer
17
     */
18
    protected $attributeNormalizer;
19
20
    /**
21
     * @var array
22
     */
23
    protected $globalContext = array();
24
25
    /**
26
     * @param AttributeNormalizer $attributeNormalizer The entity manager
27
     */
28
    public function __construct(AttributeNormalizer $attributeNormalizer)
29
    {
30
        $this->attributeNormalizer = $attributeNormalizer;
31
    }
32
33
    /**
34
     * @param  mixed                $attribute
35
     * @return array|mixed
36
     * @throws InvalidItemException
37
     */
38
    public function process($attribute)
39
    {
40
        return $this->normalizeAttribute($attribute, $this->globalContext);
41
    }
42
43
    /**
44
     * @param  Attribute            $attribute
45
     * @param  array                $context
46
     * @return array
47
     * @throws InvalidItemException
48
     */
49
    protected function normalizeAttribute(Attribute $attribute, array $context)
50
    {
51
        try {
52
            $processedItem = $this->attributeNormalizer->normalize(
53
              $attribute,
54
              $context
55
            );
56
        } catch (NormalizeException $e) {
57
            throw new InvalidItemException($e->getMessage(), [$attribute]);
58
        }
59
60
        return $processedItem;
61
    }
62
63
    public function getConfigurationFields()
64
    {
65
        return parent::getConfigurationFields();
66
    }
67
68
    /**
69
     * @param StepExecution $stepExecution
70
     */
71
    public function setStepExecution(StepExecution $stepExecution)
72
    {
73
        $this->stepExecution = $stepExecution;
74
    }
75
}
76