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 UrlRewriteAction extends AbstractAction |
|
|
|||
35 | { |
||
36 | |||
37 | /** |
||
38 | * Persist's the passed row. |
||
39 | * |
||
40 | * @param array $row The row to persist |
||
41 | * @param string|null $name The name of the prepared statement that has to be executed |
||
42 | * |
||
43 | * @return string The last inserted ID |
||
44 | */ |
||
45 | public function persist($row, $name = null) |
||
49 | |||
50 | /** |
||
51 | * Remove's the entity with the passed attributes. |
||
52 | * |
||
53 | * @param array $row The attributes of the entity to remove |
||
54 | * @param string|null $name The name of the prepared statement that has to be executed |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function remove($row, $name = null) |
||
62 | } |
||
63 |
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.