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 |
||
28 | class Table extends BaseTable |
||
29 | { |
||
30 | /** |
||
31 | * Add a Created Timestamp Column |
||
32 | * |
||
33 | * This function is a simple accessor to allow a universal design for the created timestamp. |
||
34 | * |
||
35 | * @return BaseTable The table object with a created column added. |
||
36 | */ |
||
37 | View Code Duplication | public function addCreated() |
|
49 | |||
50 | /** |
||
51 | * Add a Modified Timestamp Column |
||
52 | * |
||
53 | * This function is a simple accessor to allow a universal design for the modified timestamp. |
||
54 | * |
||
55 | * @return BaseTable The table object with a modified column added. |
||
56 | */ |
||
57 | View Code Duplication | public function addModified() |
|
69 | } |
||
70 |
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.