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 |
||
10 | class MailAPI extends API |
||
11 | { |
||
12 | /** |
||
13 | * @var Type\FolderIdType |
||
14 | */ |
||
15 | protected $folderId; |
||
16 | |||
17 | /** |
||
18 | * @return Type\FolderIdType |
||
19 | */ |
||
20 | 6 | public function getFolderId() |
|
28 | |||
29 | /** |
||
30 | * @param Type\FolderIdType $folderId |
||
31 | */ |
||
32 | 1 | public function setFolderId($folderId) |
|
36 | |||
37 | /** |
||
38 | * @param string $displayName |
||
39 | * @param string|Type\FolderIdType $parentFolder |
||
40 | */ |
||
41 | 6 | public function pickMailFolder($displayName = null, $parentFolder = 'inbox') |
|
51 | |||
52 | 1 | protected function formatRestrictions($restrictions) |
|
71 | |||
72 | /** |
||
73 | * Get all mail items in the inbox |
||
74 | * |
||
75 | * @param Type\FolderIdType |
||
76 | * @param array $options |
||
77 | * @return Type\MessageType[] |
||
78 | */ |
||
79 | 6 | public function getMailItems($folderId = null, $options = array()) |
|
104 | |||
105 | /** |
||
106 | * @param Type\FolderIdType $folderId |
||
107 | * @param array $options |
||
108 | * @return Type\MessageType[] |
||
109 | */ |
||
110 | 1 | public function getUnreadMailItems($folderId = null, $options = array()) |
|
124 | |||
125 | /** |
||
126 | * Updates a calendar item with changes |
||
127 | * |
||
128 | * @param $itemId Type\ItemIdType|Type |
||
129 | * @param $changes |
||
130 | * @return Type\MessageType[] |
||
131 | */ |
||
132 | 1 | View Code Duplication | public function updateMailItem($itemId, $changes) |
150 | |||
151 | /** |
||
152 | * @param $mailItem Type\MessageType|Type\ItemIdType |
||
153 | * @param $isRead boolean |
||
154 | */ |
||
155 | 1 | public function markMailAsRead($mailItem, $isRead = true) |
|
165 | |||
166 | 3 | public function sendMail(MessageType $message, $options = array()) |
|
183 | |||
184 | public function getAttachment(Type\AttachmentIdType $attachmentId) |
||
198 | |||
199 | /** |
||
200 | * @param array $options |
||
201 | * @return API\Message\EmptyFolderResponseType |
||
202 | */ |
||
203 | public function emptyTrash(array $options = []) |
||
212 | } |
||
213 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: