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 |
||
34 | View Code Duplication | class ProductBundleSelectionCreateProcessor extends AbstractCreateProcessor |
|
|
|||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Return's the array with the SQL statements that has to be prepared. |
||
39 | * |
||
40 | * @return array The SQL statements to be prepared |
||
41 | * @see \TechDivision\Import\Actions\Processors\AbstractBaseProcessor::getStatements() |
||
42 | */ |
||
43 | protected function getStatements() |
||
54 | |||
55 | /** |
||
56 | * Persist's the passed row. |
||
57 | * |
||
58 | * @param array $row The row to persist |
||
59 | * @param string|null $name The name of the prepared statement that has to be executed |
||
60 | * |
||
61 | * @return string The last inserted ID |
||
62 | */ |
||
63 | public function execute($row, $name = null) |
||
68 | } |
||
69 |
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.