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 |
||
11 | class DekaleeClient extends Client |
||
12 | { |
||
13 | protected $calls = []; |
||
14 | |||
15 | /** |
||
16 | * Trigger a POST request |
||
17 | * |
||
18 | * @param array $resource Mailjet Resource/Action pair |
||
19 | * @param array $args Request arguments |
||
20 | * @param array $options |
||
21 | * |
||
22 | * @return Response |
||
23 | */ |
||
24 | View Code Duplication | public function post($resource, array $args = [], array $options = []) |
|
39 | |||
40 | /** |
||
41 | * Trigger a GET request |
||
42 | * |
||
43 | * @param array $resource Mailjet Resource/Action pair |
||
44 | * @param array $args Request arguments |
||
45 | * @param array $options |
||
46 | * |
||
47 | * @return Response |
||
48 | */ |
||
49 | View Code Duplication | public function get($resource, array $args = [], array $options = []) |
|
64 | |||
65 | /** |
||
66 | * Trigger a POST request |
||
67 | * |
||
68 | * @param array $resource Mailjet Resource/Action pair |
||
69 | * @param array $args Request arguments |
||
70 | * @param array $options |
||
71 | * |
||
72 | * @return Response |
||
73 | */ |
||
74 | View Code Duplication | public function put($resource, array $args = [], array $options = []) |
|
89 | |||
90 | /** |
||
91 | * Trigger a GET request |
||
92 | * |
||
93 | * @param array $resource Mailjet Resource/Action pair |
||
94 | * @param array $args Request arguments |
||
95 | * @param array $options |
||
96 | * |
||
97 | * @return Response |
||
98 | */ |
||
99 | View Code Duplication | public function delete($resource, array $args = [], array $options = []) |
|
114 | |||
115 | /** |
||
116 | * @return array |
||
117 | */ |
||
118 | public function getCalls() |
||
122 | } |
||
123 |
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.