|
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\Family; |
|
9
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\Exception\NormalizeException; |
|
10
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer\FamilyNormalizer; |
|
11
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep; |
|
12
|
|
|
|
|
13
|
|
View Code Duplication |
class FamilyProcessor extends DrupalItemStep implements ItemProcessorInterface |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var FamilyNormalizer |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $familyNormalizer; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $globalContext = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param FamilyNormalizer $familyNormalizer The entity manager |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(FamilyNormalizer $familyNormalizer) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->familyNormalizer = $familyNormalizer; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param mixed $family |
|
35
|
|
|
* @return array|mixed |
|
36
|
|
|
* @throws InvalidItemException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function process($family) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->normalizeFamily($family, $this->globalContext); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Family $family |
|
45
|
|
|
* @param array $context |
|
46
|
|
|
* @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
47
|
|
|
* @throws InvalidItemException |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function normalizeFamily(Family $family, array $context) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
$processedItem = $this->familyNormalizer->normalize( |
|
53
|
|
|
$family, |
|
54
|
|
|
null, |
|
55
|
|
|
$this->getConfiguration() |
|
56
|
|
|
); |
|
57
|
|
|
} catch (NormalizeException $e) { |
|
58
|
|
|
throw new InvalidItemException($e->getMessage(), [$family]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $processedItem; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getConfigurationFields() |
|
65
|
|
|
{ |
|
66
|
|
|
return parent::getConfigurationFields(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param StepExecution $stepExecution |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setStepExecution(StepExecution $stepExecution) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->stepExecution = $stepExecution; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
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.