|
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\Group; |
|
9
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\Exception\NormalizeException; |
|
10
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\GroupNormalizer; |
|
11
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
12
|
|
|
|
|
13
|
|
View Code Duplication |
class GroupProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var GroupNormalizer |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $groupNormalizer; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $globalContext = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param GroupNormalizer $groupNormalizer |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(GroupNormalizer $groupNormalizer) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->groupNormalizer = $groupNormalizer; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param mixed $group |
|
35
|
|
|
* @return array|mixed |
|
36
|
|
|
* @throws InvalidItemException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function process($group) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->normalizeGroup($group, $this->globalContext); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Group $group |
|
45
|
|
|
* @param array $context |
|
46
|
|
|
* @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
47
|
|
|
* @throws InvalidItemException |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function normalizeGroup(Group $group, array $context) |
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
$processedItem = $this->groupNormalizer->normalize( |
|
53
|
|
|
$group, |
|
54
|
|
|
$context |
|
55
|
|
|
); |
|
56
|
|
|
} catch (NormalizeException $e) { |
|
57
|
|
|
throw new InvalidItemException($e->getMessage(), [$group]); |
|
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
|
|
|
|
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.