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 | View Code Duplication | class ClearUrlRewriteObserver extends AbstractProductImportObserver |
|
|
|||
37 | { |
||
38 | |||
39 | /** |
||
40 | * Will be invoked by the action on the events the listener has been registered for. |
||
41 | * |
||
42 | * @param array $row The row to handle |
||
43 | * |
||
44 | * @return array The modified row |
||
45 | * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle() |
||
46 | */ |
||
47 | public function handle(array $row) |
||
64 | |||
65 | /** |
||
66 | * Remove's the entity with the passed attributes. |
||
67 | * |
||
68 | * @param array $row The attributes of the entity to remove |
||
69 | * @param string|null $name The name of the prepared statement that has to be executed |
||
70 | * |
||
71 | * @return void |
||
72 | */ |
||
73 | public function removeUrlRewrite($row, $name = null) |
||
77 | } |
||
78 |
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.