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 |
||
18 | class CalendarAPI extends API |
||
19 | { |
||
20 | /** |
||
21 | * @var Type\FolderIdType |
||
22 | */ |
||
23 | protected $folderId; |
||
24 | |||
25 | /** |
||
26 | * Pick a Calendar based on it's name |
||
27 | * |
||
28 | * @param string|null $displayName |
||
29 | * @return $this |
||
30 | */ |
||
31 | 6 | public function pickCalendar($displayName = null) |
|
43 | |||
44 | /** |
||
45 | * @return Type\FolderIdType |
||
46 | */ |
||
47 | 6 | public function getFolderId() |
|
55 | |||
56 | /** |
||
57 | * @param Type\FolderIdType $folderId |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function setFolderId($folderId) |
||
66 | |||
67 | /** |
||
68 | * Create one or more calendar items |
||
69 | * |
||
70 | * @param $items CalendarItemType[]|CalendarItemType|array or more calendar items to create |
||
71 | * @param $options array Options to merge in to the request |
||
72 | * @return Type\ItemIdType[] |
||
73 | */ |
||
74 | 3 | public function createCalendarItems($items, $options = array()) |
|
100 | |||
101 | /** |
||
102 | * Get a list of calendar items between two dates/times |
||
103 | * |
||
104 | * @param string|DateTime $start |
||
105 | * @param string|DateTime $end |
||
106 | * @param array $options |
||
107 | * @return CalendarItemType[]|Type\FindItemParentType |
||
108 | */ |
||
109 | 6 | public function getCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
142 | |||
143 | /** |
||
144 | * @param $id |
||
145 | * @param $changeKey |
||
146 | * @return Type\CalendarItemType |
||
147 | */ |
||
148 | 1 | public function getCalendarItem($id, $changeKey) |
|
152 | |||
153 | /** |
||
154 | * Updates a calendar item with changes |
||
155 | * |
||
156 | * @param $itemId Type\ItemIdType |
||
157 | * @param $changes |
||
158 | * @return Type\CalendarItemType[] |
||
159 | */ |
||
160 | 1 | View Code Duplication | public function updateCalendarItem(Type\ItemIdType $itemId, $changes) |
182 | |||
183 | /** |
||
184 | * @param Type\ItemIdType $itemId |
||
185 | * @param array $options |
||
186 | * @return bool |
||
187 | */ |
||
188 | 3 | public function deleteCalendarItem(Type\ItemIdType $itemId, $options = array()) |
|
189 | { |
||
190 | $defaultOptions = array( |
||
191 | 'SendMeetingCancellations' => 'SendToNone' |
||
192 | 3 | ); |
|
193 | |||
194 | 3 | $options = array_replace_recursive($defaultOptions, $options); |
|
195 | 3 | return $this->deleteItems($itemId, $options); |
|
196 | } |
||
197 | |||
198 | /** |
||
199 | * @param string $start |
||
200 | * @param string $end |
||
201 | * @param array $options |
||
202 | */ |
||
203 | 6 | public function deleteAllCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
210 | |||
211 | /** |
||
212 | * Get a list of changes on the calendar items |
||
213 | * |
||
214 | * @param null $syncState |
||
215 | * @param array $options |
||
216 | * @return API\Message\SyncFolderItemsResponseMessageType |
||
217 | */ |
||
218 | 1 | public function listChanges($syncState = null, $options = array()) |
|
222 | |||
223 | /** |
||
224 | * @param Type\ItemIdType $itemId |
||
225 | * @param string $message |
||
226 | * @param string $sensitivity |
||
227 | * @param array $options |
||
228 | * |
||
229 | * @return Type\ItemIdType[] |
||
230 | */ |
||
231 | View Code Duplication | public function acceptMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
251 | |||
252 | /** |
||
253 | * @param $itemId |
||
254 | * @param $message |
||
255 | * @param string $sensitivity |
||
256 | * @param array $options |
||
257 | * @return Type\ItemIdType[] |
||
258 | */ |
||
259 | View Code Duplication | public function declineMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
279 | } |
||
280 |