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 |
||
| 23 | class PulseBoard extends SubscribableObject |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * The suffix that is appended to the URL to access functionality for certain objects |
||
| 27 | * |
||
| 28 | * @internal |
||
| 29 | */ |
||
| 30 | const API_PREFIX = "boards"; |
||
| 31 | |||
| 32 | // ================================================================================================================= |
||
| 33 | // Instance Variables |
||
| 34 | // ================================================================================================================= |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The resource's URL. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $url; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The board's name. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $name; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The board's description. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $description; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The board's visible columns. |
||
| 59 | * |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $columns; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Creation time. |
||
| 66 | * |
||
| 67 | * @var \DateTime |
||
| 68 | */ |
||
| 69 | protected $created_at; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Last update time. |
||
| 73 | * |
||
| 74 | * @var \DateTime |
||
| 75 | */ |
||
| 76 | protected $updated_at; |
||
| 77 | |||
| 78 | // ================================================================================================================= |
||
| 79 | // Getter functions |
||
| 80 | // ================================================================================================================= |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The resource's URL. |
||
| 84 | * |
||
| 85 | * @api |
||
| 86 | * |
||
| 87 | * @since 0.1.0 |
||
| 88 | * |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | 1 | public function getUrl () |
|
| 97 | |||
| 98 | /** |
||
| 99 | * The board's unique identifier. |
||
| 100 | * |
||
| 101 | * @api |
||
| 102 | * |
||
| 103 | * @since 0.1.0 |
||
| 104 | * |
||
| 105 | * @return int |
||
| 106 | */ |
||
| 107 | 43 | public function getId () |
|
| 111 | |||
| 112 | /** |
||
| 113 | * The board's name. |
||
| 114 | * |
||
| 115 | * @api |
||
| 116 | * |
||
| 117 | * @since 0.1.0 |
||
| 118 | * |
||
| 119 | * @return string |
||
| 120 | */ |
||
| 121 | 2 | public function getName () |
|
| 127 | |||
| 128 | /** |
||
| 129 | * The board's description. |
||
| 130 | * |
||
| 131 | * @api |
||
| 132 | * |
||
| 133 | * @since 0.1.0 |
||
| 134 | * |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | 2 | public function getDescription () |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Creation time. |
||
| 146 | * |
||
| 147 | * @api |
||
| 148 | * |
||
| 149 | * @since 0.1.0 |
||
| 150 | * |
||
| 151 | * @return \DateTime |
||
| 152 | */ |
||
| 153 | 1 | public function getCreatedAt () |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Last update time. |
||
| 163 | * |
||
| 164 | * @api |
||
| 165 | * |
||
| 166 | * @since 0.1.0 |
||
| 167 | * |
||
| 168 | * @return \DateTime |
||
| 169 | */ |
||
| 170 | 1 | public function getUpdatedAt () |
|
| 177 | |||
| 178 | // ================================================================================================================= |
||
| 179 | // Columns functions |
||
| 180 | // ================================================================================================================= |
||
| 181 | |||
| 182 | /** |
||
| 183 | * The board's visible columns. |
||
| 184 | * |
||
| 185 | * @api |
||
| 186 | * |
||
| 187 | * @since 0.1.0 |
||
| 188 | * |
||
| 189 | * @return PulseColumn[] |
||
| 190 | */ |
||
| 191 | 40 | public function getColumns () |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Create a new column for the current board. |
||
| 205 | * |
||
| 206 | * If you are creating a status column, use the constants available in the **PulseColumnColorValue** class to match |
||
| 207 | * the colors. Keep in mind this array cannot have a key higher than 11 nor can it be an associative array. Here's |
||
| 208 | * an example of how to match statuses with specific colors. |
||
| 209 | * |
||
| 210 | * ```php |
||
| 211 | * $labels = array( |
||
| 212 | * PulseColumnColorValue::Orange => "Working on it", |
||
| 213 | * PulseColumnColorValue::L_Green => "Done", |
||
| 214 | * PulseColumnColorValue::Red => "Delayed" |
||
| 215 | * ); |
||
| 216 | * ``` |
||
| 217 | * |
||
| 218 | * @api |
||
| 219 | * |
||
| 220 | * @param string $title The title of the column. This title will automatically be "slugified" and become the ID |
||
| 221 | * of the column. |
||
| 222 | * @param string $type The type of value that this column will use. Either use the available constants in the |
||
| 223 | * PulseColumn class or use the following strings: "date", "person", "status", "text". |
||
| 224 | * @param array $labels If the column type will be "status," then this array will be the values for each of the |
||
| 225 | * colors. |
||
| 226 | * |
||
| 227 | * @see PulseColumn::Date PulseColumn::Date |
||
| 228 | * @see PulseColumn::Person PulseColumn::Person |
||
| 229 | * @see PulseColumn::Numeric PulseColumn::Numeric |
||
| 230 | * @see PulseColumn::Status PulseColumn::Status |
||
| 231 | * @see PulseColumn::Text PulseColumn::Text |
||
| 232 | * @see PulseColumnStatusValue::Orange PulseColumnStatusValue::Orange |
||
| 233 | * @see PulseColumnStatusValue::L_Green PulseColumnStatusValue::L_Green |
||
| 234 | * @see PulseColumnStatusValue::Red PulseColumnStatusValue::Red |
||
| 235 | * @see PulseColumnStatusValue::Blue PulseColumnStatusValue::Blue |
||
| 236 | * @see PulseColumnStatusValue::Purple PulseColumnStatusValue::Purple |
||
| 237 | * @see PulseColumnStatusValue::Grey PulseColumnStatusValue::Grey |
||
| 238 | * @see PulseColumnStatusValue::Green PulseColumnStatusValue::Green |
||
| 239 | * @see PulseColumnStatusValue::L_Blue PulseColumnStatusValue::L_Blue |
||
| 240 | * @see PulseColumnStatusValue::Gold PulseColumnStatusValue::Gold |
||
| 241 | * @see PulseColumnStatusValue::Yellow PulseColumnStatusValue::Yellow |
||
| 242 | * @see PulseColumnStatusValue::Black PulseColumnStatusValue::Black |
||
| 243 | * |
||
| 244 | * @since 0.1.0 |
||
| 245 | * |
||
| 246 | * @throws ArgumentMismatchException Status definitions were defined yet the type of the column was not a status |
||
| 247 | * type column |
||
| 248 | * @throws InvalidArraySizeException The array containing the value of statuses has a key larger than the |
||
| 249 | * supported 10 indices |
||
| 250 | * |
||
| 251 | * @return $this This instance will be updated to have updated information to reflect the new column that was |
||
| 252 | * created |
||
| 253 | */ |
||
| 254 | 3 | public function createColumn ($title, $type, $labels = []) |
|
| 279 | |||
| 280 | // ================================================================================================================= |
||
| 281 | // Group functions |
||
| 282 | // ================================================================================================================= |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Get all of the groups belonging to a board. |
||
| 286 | * |
||
| 287 | * A group is defined as the colorful headers that split up pulses into categories. |
||
| 288 | * |
||
| 289 | * @api |
||
| 290 | * |
||
| 291 | * @param bool $showArchived Set to true if you would like to get archived groups in a board as well |
||
| 292 | * |
||
| 293 | * @since 0.1.0 |
||
| 294 | * |
||
| 295 | * @return PulseGroup[] |
||
| 296 | */ |
||
| 297 | 3 | public function getGroups ($showArchived = false) |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Create a new group in a board |
||
| 315 | * |
||
| 316 | * @api |
||
| 317 | * |
||
| 318 | * @param string $title The title of the board |
||
| 319 | * |
||
| 320 | * @since 0.1.0 |
||
| 321 | * |
||
| 322 | * @return PulseGroup |
||
| 323 | */ |
||
| 324 | 1 | public function createGroup ($title) |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Delete a group from a board |
||
| 338 | * |
||
| 339 | * @api |
||
| 340 | * |
||
| 341 | * @param string $groupId The group ID to be deleted |
||
| 342 | * |
||
| 343 | * @since 0.3.0 An array of PulseGroup objects representing the current groups in this board and their states |
||
| 344 | * @since 0.1.0 |
||
| 345 | * |
||
| 346 | * @return PulseGroup[] An array containing the remaining groups available on the board |
||
| 347 | */ |
||
| 348 | 1 | public function deleteGroup ($groupId) |
|
| 360 | |||
| 361 | // ================================================================================================================= |
||
| 362 | // Pulse functions |
||
| 363 | // ================================================================================================================= |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Get all of the Pulses belonging to this board |
||
| 367 | * |
||
| 368 | * @api |
||
| 369 | * |
||
| 370 | * @since 0.1.0 |
||
| 371 | * |
||
| 372 | * @param int $perPage default: 15, max: 25 |
||
| 373 | * @param int $page default: 1 |
||
| 374 | * @return Pulse[] |
||
| 375 | */ |
||
| 376 | 40 | public function getPulses ($perPage = null, $page = null) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Create a new Pulse inside of this board |
||
| 399 | * |
||
| 400 | * Using the $updateText and $announceToAll parameters is the equivalent of using Pulse::createUpdate() after a |
||
| 401 | * Pulse has been created but with one less API call. |
||
| 402 | * |
||
| 403 | * @api |
||
| 404 | * |
||
| 405 | * @param string $name The name of the Pulse |
||
| 406 | * @param PulseUser|int $user The owner of the Pulse, i.e. who created it |
||
| 407 | * @param string|null $groupId The group to add this Pulse to |
||
| 408 | * @param string|null $updateText The update's text, can contain simple HTML for formatting |
||
| 409 | * @param bool|null $announceToAll Determines if the update should be sent to everyone's wall |
||
| 410 | * |
||
| 411 | * @throws \InvalidArgumentException if $user is not a valid user by definition |
||
| 412 | * |
||
| 413 | * @since 0.3.0 An \InvalidArgumentException may be thrown |
||
| 414 | * @since 0.1.0 |
||
| 415 | * |
||
| 416 | * @return Pulse |
||
| 417 | */ |
||
| 418 | 1 | public function createPulse ($name, $user, $groupId = null, $updateText = null, $announceToAll = null) |
|
| 438 | |||
| 439 | 40 | View Code Duplication | private function pulseInjection (&$result) |
| 446 | |||
| 447 | // ================================================================================================================= |
||
| 448 | // Board functions |
||
| 449 | // ================================================================================================================= |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Archive this board |
||
| 453 | * |
||
| 454 | * @api |
||
| 455 | * |
||
| 456 | * @since 0.1.0 |
||
| 457 | * |
||
| 458 | * @throws InvalidObjectException if the object has already been deleted |
||
| 459 | */ |
||
| 460 | 1 | View Code Duplication | public function archiveBoard () |
| 469 | |||
| 470 | /** |
||
| 471 | * Create a new board |
||
| 472 | * |
||
| 473 | * @api |
||
| 474 | * |
||
| 475 | * @param string $name The name of the board |
||
| 476 | * @param int|PulseUser $user The owner of the board |
||
| 477 | * @param string|null $description A description of the board |
||
| 478 | * |
||
| 479 | * @since 0.3.0 $userId may be a PulseUser object and \InvalidArgumentException is now thrown |
||
| 480 | * @since 0.1.0 |
||
| 481 | * |
||
| 482 | * @throws \InvalidArgumentException if $user is not a valid user by definition |
||
| 483 | * |
||
| 484 | * @return PulseBoard |
||
| 485 | */ |
||
| 486 | 1 | public static function createBoard ($name, $user, $description = null) |
|
| 501 | |||
| 502 | /** |
||
| 503 | * Get all the account's boards |
||
| 504 | * |
||
| 505 | * ``` |
||
| 506 | * array['page'] int - Page offset to fetch |
||
| 507 | * ['per_page'] int - Number of results to return per page |
||
| 508 | * ['offset'] int - Pad a number of results |
||
| 509 | * ['only_globals'] bool - Return only global boards |
||
| 510 | * ['order_by_latest'] bool - Order by newest boards |
||
| 511 | * ``` |
||
| 512 | * |
||
| 513 | * @api |
||
| 514 | * |
||
| 515 | * @param array $params Parameters to filter the boards (see above) |
||
| 516 | * |
||
| 517 | * @since 0.1.0 |
||
| 518 | * |
||
| 519 | * @return PulseBoard[] |
||
| 520 | */ |
||
| 521 | 1 | public static function getBoards ($params = []) |
|
| 527 | } |
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..