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 |
||
| 17 | class CalendarAPI extends API |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var Type\BaseFolderIdType |
||
| 21 | */ |
||
| 22 | protected $folderId; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Pick a Calendar based on it's name |
||
| 26 | * |
||
| 27 | * @param string|null $displayName |
||
| 28 | * @return $this |
||
| 29 | */ |
||
| 30 | 6 | public function pickCalendar($displayName = null) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @return Type\BaseFolderIdType |
||
| 43 | */ |
||
| 44 | 6 | public function getFolderId() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param Type\BaseFolderIdType $folderId |
||
| 55 | * @return $this |
||
| 56 | */ |
||
| 57 | public function setFolderId($folderId) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Create one or more calendar items |
||
| 66 | * |
||
| 67 | * @param $items CalendarItemType[]|CalendarItemType|array or more calendar items to create |
||
| 68 | * @param $options array Options to merge in to the request |
||
| 69 | * @return Type\ItemIdType[] |
||
| 70 | */ |
||
| 71 | 3 | public function createCalendarItems($items, $options = array()) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Get a list of calendar items between two dates/times |
||
| 88 | * |
||
| 89 | * @param string|DateTime $start |
||
| 90 | * @param string|DateTime $end |
||
| 91 | * @param array $options |
||
| 92 | * @return CalendarItemType[]|Type\FindItemParentType |
||
| 93 | */ |
||
| 94 | 6 | public function getCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * @param $id |
||
| 123 | * @param $changeKey |
||
| 124 | * @return Type\CalendarItemType |
||
| 125 | */ |
||
| 126 | 1 | public function getCalendarItem($id, $changeKey) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Updates a calendar item with changes |
||
| 133 | * |
||
| 134 | * @param $itemId Type\ItemIdType |
||
| 135 | * @param array $changes |
||
| 136 | * @param array $options |
||
| 137 | * @return Type\CalendarItemType[] |
||
| 138 | */ |
||
| 139 | 1 | public function updateCalendarItem(Type\ItemIdType $itemId, $changes, $options = array()) |
|
| 157 | |||
| 158 | /** |
||
| 159 | * @param Type\ItemIdType $itemId |
||
| 160 | * @param array $options |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | 3 | public function deleteCalendarItem(Type\ItemIdType $itemId, $options = array()) |
|
| 172 | |||
| 173 | /** |
||
| 174 | * @param string $start |
||
| 175 | * @param string $end |
||
| 176 | * @param array $options |
||
| 177 | */ |
||
| 178 | 6 | public function deleteAllCalendarItems($start = '12:00 AM', $end = '11:59 PM', $options = array()) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * Get a list of changes on the calendar items |
||
| 188 | * |
||
| 189 | * @param null $syncState |
||
| 190 | * @param array $options |
||
| 191 | * @return API\Message\SyncFolderItemsResponseMessageType |
||
| 192 | */ |
||
| 193 | 1 | public function listChanges($syncState = null, $options = array()) |
|
| 197 | |||
| 198 | /** |
||
| 199 | * @param Type\ItemIdType $itemId |
||
| 200 | * @param string $message |
||
| 201 | * @param string $sensitivity |
||
| 202 | * @param array $options |
||
| 203 | * |
||
| 204 | * @return Type\ItemIdType[] |
||
| 205 | */ |
||
| 206 | View Code Duplication | public function acceptMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @param $itemId |
||
| 225 | * @param $message |
||
| 226 | * @param string $sensitivity |
||
| 227 | * @param array $options |
||
| 228 | * @return Type\ItemIdType[] |
||
| 229 | */ |
||
| 230 | View Code Duplication | public function declineMeeting($itemId, $message, $sensitivity = 'Private', $options = array()) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * @param $startTime |
||
| 249 | * @param $endTime |
||
| 250 | * @param array $users |
||
| 251 | * @param array $options |
||
| 252 | * |
||
| 253 | * @return API\Message\GetUserAvailabilityResponseType |
||
| 254 | */ |
||
| 255 | public function getAvailabilityFor($startTime, $endTime, array $users, array $options = array()) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param $startTime |
||
| 289 | * @param $endTime |
||
| 290 | * @param int $period The period of time to see if users of free for (in minutes) |
||
| 291 | * @param array $users |
||
| 292 | * @param array $options |
||
| 293 | * |
||
| 294 | * @return boolean |
||
| 295 | */ |
||
| 296 | public function areAvailable($startTime, $endTime, $period, array $users, array $options = []) |
||
| 330 | } |
||
| 331 |
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..