AttributeProcessor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A process() 4 4 1
A normalizeAttribute() 13 13 2
A getConfigurationFields() 4 4 1
A setStepExecution() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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