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 |
||
31 | class Mailboxes extends AriClientAware |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * List all mailboxes. |
||
36 | * |
||
37 | * @return Mailbox[] |
||
38 | */ |
||
39 | 1 | public function getMailboxes() |
|
51 | |||
52 | /** |
||
53 | * Retrieve the current state of a mailbox. |
||
54 | * |
||
55 | * @param string $mailboxName Name of the mailbox |
||
56 | * @return Mailbox |
||
57 | * @throws NotFoundException |
||
58 | */ |
||
59 | 2 | public function getMailbox($mailboxName) |
|
70 | |||
71 | /** |
||
72 | * Change the state of a mailbox. (Note - implicitly creates the mailbox). |
||
73 | * |
||
74 | * @param string $mailboxName Name of the mailbox |
||
75 | * @param int $oldMessages (required) Count of old messages in the mailbox |
||
76 | * @param int $newMessages (required) Count of new messages in the mailbox |
||
77 | * @throws NotFoundException |
||
78 | */ |
||
79 | 1 | public function updateMailbox($mailboxName, $oldMessages, $newMessages) |
|
91 | |||
92 | /** |
||
93 | * Destroy a mailbox. |
||
94 | * |
||
95 | * @param string $mailboxName Name of the mailbox |
||
96 | * @throws NotFoundException |
||
97 | */ |
||
98 | 2 | View Code Duplication | public function deleteMailbox($mailboxName) |
107 | |||
108 | } |
||
109 |
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.