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 |
||
| 8 | class ContactsAPI extends API |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var Type\BaseFolderIdType |
||
| 12 | */ |
||
| 13 | protected $folderId; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Pick a Contacts based on it's folder name |
||
| 17 | * |
||
| 18 | * @param string|null $displayName |
||
| 19 | * @return $this |
||
| 20 | * @throws Exception |
||
| 21 | */ |
||
| 22 | 5 | public function pickContactsFolder($displayName = null) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return Type\BaseFolderIdType |
||
| 39 | */ |
||
| 40 | 5 | public function getFolderId() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @param Type\BaseFolderIdType $folderId |
||
| 51 | */ |
||
| 52 | 5 | public function setFolderId($folderId) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param Type\BaseFolderIdType $folderId |
||
| 59 | * @param array $options |
||
| 60 | * @return Type\ContactItemType[] |
||
| 61 | */ |
||
| 62 | 2 | View Code Duplication | public function getContacts($folderId = null, $options = array()) |
| 82 | |||
| 83 | /** |
||
| 84 | * @param Type\ItemIdType $itemId |
||
| 85 | * @return Type\ContactItemType |
||
| 86 | */ |
||
| 87 | 3 | public function getContact($itemId) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param $contacts |
||
| 94 | * @param array $options |
||
| 95 | * @return Type\ItemIdType[] |
||
| 96 | */ |
||
| 97 | 5 | public function createContacts($contacts, $options = array()) |
|
| 115 | |||
| 116 | 2 | View Code Duplication | public function updateContactItem(Type\ItemIdType $itemId, $changes) |
| 136 | } |
||
| 137 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..