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 |
||
| 9 | class MailAPI extends API |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Type\FolderIdType |
||
| 13 | */ |
||
| 14 | protected $folderId; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @return Type\FolderIdType |
||
| 18 | */ |
||
| 19 | 6 | public function getFolderId() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param Type\FolderIdType $folderId |
||
| 30 | */ |
||
| 31 | 1 | public function setFolderId($folderId) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @param string $displayName |
||
| 38 | * @param string|Type\FolderIdType $parentFolder |
||
| 39 | */ |
||
| 40 | 6 | public function pickMailFolder($displayName = null, $parentFolder = 'inbox') |
|
| 50 | |||
| 51 | 1 | protected function formatRestrictions($restrictions) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Get all mail items in the inbox |
||
| 73 | * |
||
| 74 | * @param Type\FolderIdType |
||
| 75 | * @param array $options |
||
| 76 | * @return Type\MessageType[] |
||
| 77 | */ |
||
| 78 | 6 | public function getMailItems($folderId = null, $options = array()) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @param Type\FolderIdType $folderId |
||
| 106 | * @param array $options |
||
| 107 | * @return Type\MessageType[] |
||
| 108 | */ |
||
| 109 | 1 | public function getUnreadMailItems($folderId = null, $options = array()) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Updates a calendar item with changes |
||
| 126 | * |
||
| 127 | * @param $itemId Type\ItemIdType|Type |
||
| 128 | * @param $changes |
||
| 129 | * @return Type\MessageType[] |
||
| 130 | */ |
||
| 131 | 1 | View Code Duplication | public function updateMailItem($itemId, $changes) |
| 149 | |||
| 150 | /** |
||
| 151 | * @param $mailItem Type\MessageType|Type\ItemIdType |
||
| 152 | * @param $isRead boolean |
||
| 153 | */ |
||
| 154 | 1 | public function markMailAsRead($mailItem, $isRead = true) |
|
| 164 | |||
| 165 | 3 | public function sendMail(MessageType $message, $options = array()) |
|
| 182 | |||
| 183 | public function getAttachment(Type\AttachmentIdType $attachmentId) |
||
| 197 | } |
||
| 198 |
If you implement
__calland 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
__callis implemented by a parent class and only the child class knows which methods exist: