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 |
||
42 | View Code Duplication | class EeBundleSelectionUpdateObserver extends BundleSelectionUpdateObserver |
|
|
|||
43 | { |
||
44 | |||
45 | /** |
||
46 | * The sequence product bundle selection action instance. |
||
47 | * |
||
48 | * @var \TechDivision\Import\Product\Bundle\Ee\Actions\SequenceProductBundleSelectionActionInterface |
||
49 | */ |
||
50 | protected $sequenceProductBundleSelectionAction; |
||
51 | |||
52 | /** |
||
53 | * Initialize the observer with the passed product bundle processor instance. |
||
54 | * |
||
55 | * @param \TechDivision\Import\Product\Bundle\Services\ProductBundleProcessorInterface $productBundleProcessor The product bundle processor instance |
||
56 | * @param \TechDivision\Import\Product\Bundle\Ee\Actions\SequenceProductBundleSelectionActionInterface $sequenceProductBundleSelectionAction The action instance |
||
57 | * @param \TechDivision\Import\Observers\AttributeLoaderInterface|null $attributeLoader The attribute loader instance |
||
58 | * @param \TechDivision\Import\Observers\EntityMergers\EntityMergerInterface $entityMerger The entity merger instance |
||
59 | * @param \TechDivision\Import\Observers\StateDetectorInterface|null $stateDetector The state detector instance |
||
60 | */ |
||
61 | public function __construct( |
||
75 | |||
76 | /** |
||
77 | * Prepare the attributes of the entity that has to be persisted. |
||
78 | * |
||
79 | * @return array The prepared attributes |
||
80 | */ |
||
81 | protected function prepareAttributes() |
||
95 | |||
96 | /** |
||
97 | * Returns the sequence product bundle selection action instance. |
||
98 | * |
||
99 | * @return \TechDivision\Import\Product\Bundle\Ee\Actions\SequenceProductBundleSelectionActionInterface The action instance |
||
100 | */ |
||
101 | protected function getSequenceProductBundleSelectionAction() |
||
105 | |||
106 | /** |
||
107 | * Returns the next available product bundle option ID. |
||
108 | * |
||
109 | * @return integer The next available product bundle option ID |
||
110 | */ |
||
111 | protected function nextIdentifier() |
||
115 | |||
116 | /** |
||
117 | * Returns the row ID for the passed SKU. |
||
118 | * |
||
119 | * @param string $sku The SKU to return the row ID for |
||
120 | * |
||
121 | * @return integer The mapped row ID |
||
122 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
123 | */ |
||
124 | protected function mapSku($sku) |
||
128 | } |
||
129 |
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.