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 | * Pick a Contacts based on it's folder name |
||
16 | * |
||
17 | * @param string|null $displayName |
||
18 | * @return $this |
||
19 | */ |
||
20 | View Code Duplication | public function pickContact($displayName = null) |
|
33 | |||
34 | /** |
||
35 | * @return Type\FolderIdType |
||
36 | */ |
||
37 | 5 | public function getFolderId() |
|
45 | |||
46 | /** |
||
47 | * @param Type\FolderIdType $folderId |
||
48 | */ |
||
49 | 5 | public function setFolderId($folderId) |
|
53 | |||
54 | /** |
||
55 | * @param Type\FolderIdType $folderId |
||
56 | * @param array $options |
||
57 | * @return Type\ContactItemType[] |
||
58 | */ |
||
59 | 2 | View Code Duplication | public function getContacts($folderId = null, $options = array()) |
81 | |||
82 | /** |
||
83 | * @param Type\ItemIdType $itemId |
||
84 | * @return Type\ContactItemType |
||
85 | */ |
||
86 | 3 | public function getContact($itemId) |
|
90 | |||
91 | /** |
||
92 | * @param $contacts |
||
93 | * @param array $options |
||
94 | * @return Type\ItemIdType[] |
||
95 | */ |
||
96 | 5 | View Code Duplication | public function createContacts($contacts, $options = array()) |
114 | |||
115 | 2 | View Code Duplication | public function updateContactItem(Type\ItemIdType $itemId, $changes) |
135 | } |
||
136 |