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 |
||
23 | class ContactEmailController extends RestController implements ClassResourceInterface |
||
24 | { |
||
25 | /** |
||
26 | * Create entity ContactEmail |
||
27 | * oro_api_post_contact_email |
||
28 | ** |
||
29 | * @return Response |
||
30 | * |
||
31 | * @ApiDoc( |
||
32 | * description="Create entity", |
||
33 | * resource=true, |
||
34 | * requirements = { |
||
35 | * {"name"="id", "dataType"="integer"}, |
||
36 | * } |
||
37 | * ) |
||
38 | */ |
||
39 | public function postAction() |
||
45 | |||
46 | /** |
||
47 | * Delete entity ContactEmail |
||
48 | * oro_api_delete_contact_email |
||
49 | * |
||
50 | * @param int $id |
||
51 | * |
||
52 | * @ApiDoc( |
||
53 | * description="Delete ContactEmail" |
||
54 | * ) |
||
55 | * |
||
56 | * @return Response |
||
57 | */ |
||
58 | View Code Duplication | public function deleteAction($id) |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function getManager() |
||
76 | |||
77 | /** |
||
78 | * @return ApiFormHandler |
||
79 | */ |
||
80 | public function getFormHandler() |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function getForm() |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getDeleteHandler() |
||
100 | } |
||
101 |
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.