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 |
||
12 | View Code Duplication | class SegmentsRequest |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @param Mailxpert $mailxpert |
||
16 | * @param array $params |
||
17 | * |
||
18 | * @return \Mailxpert\MailxpertResponse |
||
19 | * @throws MailxpertSDKResponseException |
||
20 | */ |
||
21 | public static function get(Mailxpert $mailxpert, array $params = []) |
||
31 | |||
32 | /** |
||
33 | * @param Mailxpert $mailxpert |
||
34 | * @param array $params |
||
35 | * |
||
36 | * @return \Mailxpert\MailxpertResponse |
||
37 | * @throws MailxpertSDKResponseException |
||
38 | */ |
||
39 | public static function post(Mailxpert $mailxpert, array $params) |
||
49 | |||
50 | /** |
||
51 | * @param Mailxpert $mailxpert |
||
52 | * @param string $id |
||
53 | * @param array $params |
||
54 | * |
||
55 | * @return \Mailxpert\MailxpertResponse |
||
56 | * @throws MailxpertSDKResponseException |
||
57 | */ |
||
58 | public static function patch(Mailxpert $mailxpert, $id, array $params) |
||
68 | |||
69 | /** |
||
70 | * @param Mailxpert $mailxpert |
||
71 | * @param string $id |
||
72 | * |
||
73 | * @return \Mailxpert\MailxpertResponse |
||
74 | * @throws MailxpertSDKResponseException |
||
75 | */ |
||
76 | public static function delete(Mailxpert $mailxpert, $id) |
||
86 | } |
||
87 |
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.