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 |
||
5 | class Message extends BaseClass |
||
6 | { |
||
7 | /** The URI of the action */ |
||
8 | const URI = 'https://api.signere.no/api/Message'; |
||
9 | |||
10 | /** |
||
11 | * Get a list of messages sent for the given document ID. |
||
12 | * |
||
13 | * @param string $messageId |
||
14 | * @return object |
||
15 | */ |
||
16 | 1 | public function get(string $messageId) |
|
32 | |||
33 | /** |
||
34 | * Retrieves a list of all the messages that |
||
35 | * are sent for the given document. |
||
36 | * |
||
37 | * @param string $documentId |
||
38 | * @return object |
||
39 | */ |
||
40 | 1 | public function all(string $documentId) |
|
56 | |||
57 | /** |
||
58 | * Sends a message to the signees of a given document. |
||
59 | * |
||
60 | * @param array $body |
||
61 | * @return object |
||
62 | */ |
||
63 | 1 | public function sendMessage(array $body) |
|
80 | |||
81 | /** |
||
82 | * Sends a new message to the Signeeref if the first one failed. |
||
83 | * |
||
84 | * @param array $body |
||
85 | * @return object |
||
86 | */ |
||
87 | 1 | View Code Duplication | public function sendNewMessage(array $body) |
104 | |||
105 | /** |
||
106 | * Sends a message to an external person with a link/URL |
||
107 | * to view a document. |
||
108 | * |
||
109 | * @param array $body |
||
110 | * @return object |
||
111 | */ |
||
112 | 1 | View Code Duplication | public function sendExternalMessage(array $body) |
129 | } |
||
130 |
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.