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 |
||
| 7 | class ContactsAPI extends API |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var Type\FolderIdType |
||
| 11 | */ |
||
| 12 | protected $folderId; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @return Type\FolderIdType |
||
| 16 | */ |
||
| 17 | public function getFolderId() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Type\FolderIdType $folderId |
||
| 28 | */ |
||
| 29 | public function setFolderId($folderId) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param Type\FolderIdType $folderId |
||
| 36 | * @param array $options |
||
| 37 | * @return Type\ContactItemType[] |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function getContacts($folderId = null, $options = array()) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @param Type\ItemIdType $itemId |
||
| 64 | * @return Type\ContactItemType |
||
| 65 | */ |
||
| 66 | public function getContact($itemId) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param $contacts |
||
| 73 | * @param array $options |
||
| 74 | * @return Type\ItemIdType[] |
||
| 75 | */ |
||
| 76 | View Code Duplication | public function createContacts($contacts, $options = array()) |
|
| 94 | |||
| 95 | View Code Duplication | public function updateContactItem(Type\ItemIdType $itemId, $changes) |
|
| 115 | } |
||
| 116 |
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: