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 |
||
36 | class PreLoadAttributeOptionIdObserver extends AbstractAttributeImportObserver |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The attribute processor instance. |
||
41 | * |
||
42 | * @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface |
||
43 | */ |
||
44 | protected $attributeBunchProcessor; |
||
45 | |||
46 | /** |
||
47 | * Initializes the observer with the passed subject instance. |
||
48 | * |
||
49 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
50 | */ |
||
51 | public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor) |
||
55 | |||
56 | /** |
||
57 | * Return's the attribute bunch processor instance. |
||
58 | * |
||
59 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
60 | */ |
||
61 | protected function getAttributeBunchProcessor() |
||
65 | |||
66 | /** |
||
67 | * Process the observer's business logic. |
||
68 | * |
||
69 | * @return array The processed row |
||
70 | */ |
||
71 | View Code Duplication | protected function process() |
|
93 | |||
94 | /** |
||
95 | * Queries whether or not the option with the passed code/value has already been processed. |
||
96 | * |
||
97 | * @param string $attributeCode The attribute code to check |
||
98 | * @param string $value The option value to check |
||
99 | * |
||
100 | * @return boolean TRUE if the path has been processed, else FALSE |
||
101 | */ |
||
102 | protected function hasBeenProcessed($attributeCode, $value) |
||
106 | |||
107 | /** |
||
108 | * Pre-load the option ID for the passed EAV attribute option. |
||
109 | * |
||
110 | * @param array $attributeOption The EAV attribute option with the ID that has to be pre-loaded |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | protected function preLoadOptionId(array $attributeOption) |
||
118 | } |
||
119 |
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.