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\BaseFolderIdType |
||
| 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) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @return Type\BaseFolderIdType |
||
| 44 | */ |
||
| 45 | 6 | public function getFolderId() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * @param Type\BaseFolderIdType $folderId |
||
| 56 | * @return $this |
||
| 57 | */ |
||
| 58 | public function setFolderId($folderId) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Create one or more calendar items |
||
| 67 | * |
||
| 68 | * @param $items CalendarItemType[]|CalendarItemType|array or more calendar items to create |
||
| 69 | * @param $options array Options to merge in to the request |
||
| 70 | * @return Type\ItemIdType[] |
||
| 71 | */ |
||
| 72 | 3 | public function createCalendarItems($items, $options = array()) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Get a list of calendar items between two dates/times |
||
| 89 | * |
||
| 90 | * @param string|DateTime $start |
||
| 91 | * @param string|DateTime $end |
||
| 92 | * @param array $options |
||
| 93 | * @return CalendarItemType[]|Type\FindItemParentType |
||
| 94 | */ |
||
| 95 | 6 | public function getCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @param $id |
||
| 124 | * @param $changeKey |
||
| 125 | * @param array $options |
||
| 126 | * @return Type\CalendarItemType |
||
| 127 | */ |
||
| 128 | 1 | public function getCalendarItem($id, $changeKey, $options = []) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Updates a calendar item with changes |
||
| 135 | * |
||
| 136 | * @param $itemId Type\ItemIdType |
||
| 137 | * @param array $changes |
||
| 138 | * @param array $options |
||
| 139 | * @return Type\CalendarItemType[] |
||
| 140 | */ |
||
| 141 | 1 | public function updateCalendarItem(Type\ItemIdType $itemId, $changes, $options = array()) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @param Type\ItemIdType $itemId |
||
| 162 | * @param array $options |
||
| 163 | * @return bool |
||
| 164 | */ |
||
| 165 | 3 | public function deleteCalendarItem(Type\ItemIdType $itemId, $options = array()) |
|
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $start |
||
| 177 | * @param string $end |
||
| 178 | * @param array $options |
||
| 179 | */ |
||
| 180 | 6 | public function deleteAllCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Get a list of changes on the calendar items |
||
| 190 | * |
||
| 191 | * @param null $syncState |
||
| 192 | * @param array $options |
||
| 193 | * @return API\Message\SyncFolderItemsResponseMessageType |
||
| 194 | */ |
||
| 195 | 1 | public function listChanges($syncState = null, $options = array()) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param Type\ItemIdType $itemId |
||
| 202 | * @param string $message |
||
| 203 | * @param string $sensitivity |
||
| 204 | * @param array $options |
||
| 205 | * |
||
| 206 | * @return Type\ItemIdType[] |
||
| 207 | */ |
||
| 208 | View Code Duplication | public function acceptMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * @param $itemId |
||
| 227 | * @param $message |
||
| 228 | * @param string $sensitivity |
||
| 229 | * @param array $options |
||
| 230 | * @return Type\ItemIdType[] |
||
| 231 | */ |
||
| 232 | View Code Duplication | public function declineMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * @param $startTime |
||
| 251 | * @param $endTime |
||
| 252 | * @param array $users |
||
| 253 | * @param array $options |
||
| 254 | * |
||
| 255 | * @return API\Message\GetUserAvailabilityResponseType |
||
| 256 | */ |
||
| 257 | public function getAvailabilityFor($startTime, $endTime, array $users, array $options = array()) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @param $startTime |
||
| 291 | * @param $endTime |
||
| 292 | * @param int $period The period of time to see if users of free for (in minutes) |
||
| 293 | * @param array $users |
||
| 294 | * @param array $options |
||
| 295 | * |
||
| 296 | * @return boolean |
||
| 297 | * @throws ExchangeException |
||
| 298 | */ |
||
| 299 | public function areAvailable($startTime, $endTime, $period, array $users, array $options = []) |
||
| 338 | } |
||
| 339 |
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..