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 |
||
| 30 | class Pulse extends SubscribableObject |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @ignore |
||
| 34 | */ |
||
| 35 | const API_PREFIX = "pulses"; |
||
| 36 | |||
| 37 | // ================================================================================================================ |
||
| 38 | // Instance Variables |
||
| 39 | // ================================================================================================================ |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The resource's URL. |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $url; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The pulse's name. |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | protected $name; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The board's subscribers. |
||
| 57 | * |
||
| 58 | * @var PulseUser[] |
||
| 59 | */ |
||
| 60 | protected $subscribers; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The amount of updates a pulse has. |
||
| 64 | * |
||
| 65 | * @var int |
||
| 66 | */ |
||
| 67 | protected $updates_count; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The ID of the parent board. |
||
| 71 | * |
||
| 72 | * @var int |
||
| 73 | */ |
||
| 74 | protected $board_id; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Creation time. |
||
| 78 | * |
||
| 79 | * @var \DateTime |
||
| 80 | */ |
||
| 81 | protected $created_at; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Last update time. |
||
| 85 | * |
||
| 86 | * @var \DateTime |
||
| 87 | */ |
||
| 88 | protected $updated_at; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * The ID of the group this pulse belongs to |
||
| 92 | * |
||
| 93 | * @var string |
||
| 94 | */ |
||
| 95 | protected $group_id; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var PulseColumn[] |
||
| 99 | */ |
||
| 100 | protected $column_structure; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * An array containing all of the values a pulse has for each column |
||
| 104 | * |
||
| 105 | * @var mixed |
||
| 106 | */ |
||
| 107 | protected $raw_column_values; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * An array containing objects extended from PulseColumnValue storing all of the values for each column |
||
| 111 | * |
||
| 112 | * @var array |
||
| 113 | */ |
||
| 114 | protected $column_values; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates |
||
| 118 | * |
||
| 119 | * @var string |
||
| 120 | */ |
||
| 121 | private $urlSyntax = "%s/%s/%s.json"; |
||
| 122 | |||
| 123 | // ================================================================================================================ |
||
| 124 | // Overloaded functions |
||
| 125 | // ================================================================================================================ |
||
| 126 | |||
| 127 | protected function initializeValues () |
||
| 128 | { |
||
| 129 | $this->column_values = array(); |
||
| 130 | $this->column_structure = array(); |
||
| 131 | $this->raw_column_values = array(); |
||
| 132 | } |
||
| 133 | |||
| 134 | // ================================================================================================================ |
||
| 135 | // Getter functions |
||
| 136 | // ================================================================================================================ |
||
| 137 | |||
| 138 | /** |
||
| 139 | * The resource's URL. |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getUrl () |
||
| 147 | |||
| 148 | /** |
||
| 149 | * The pulse's name. |
||
| 150 | * |
||
| 151 | * @return string |
||
| 152 | */ |
||
| 153 | public function getName () |
||
| 157 | |||
| 158 | /** |
||
| 159 | * The amount of updates a pulse has. |
||
| 160 | * |
||
| 161 | * @return int |
||
| 162 | */ |
||
| 163 | public function getUpdatesCount () |
||
| 167 | |||
| 168 | /** |
||
| 169 | * The ID of the parent board. |
||
| 170 | * |
||
| 171 | * @return int |
||
| 172 | */ |
||
| 173 | public function getBoardId () |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Creation time. |
||
| 180 | * |
||
| 181 | * @return \DateTime |
||
| 182 | */ |
||
| 183 | public function getCreatedAt () |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Last update time. |
||
| 192 | * |
||
| 193 | * @return \DateTime |
||
| 194 | */ |
||
| 195 | public function getUpdatedAt () |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get the ID of the group this Pulse is a part of. If this value is not available, an API call will be made to |
||
| 204 | * find the group ID via brute force. |
||
| 205 | * |
||
| 206 | * **Note** The group ID is cached if it is not available. To update the cached value, use $forceFetch to force an |
||
| 207 | * API call to get a new value. |
||
| 208 | * |
||
| 209 | * **Warning** An API call is always slower than using the cached value. |
||
| 210 | * |
||
| 211 | * @param bool $forceFetch Force an API call to get an updated group ID if it has been changed |
||
| 212 | * |
||
| 213 | * @since 0.1.0 |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getGroupId ($forceFetch = false) |
||
| 235 | |||
| 236 | // ================================================================================================================ |
||
| 237 | // Pulse functions |
||
| 238 | // ================================================================================================================ |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Edit the name of the pulse |
||
| 242 | * |
||
| 243 | * @api |
||
| 244 | * @param string $title |
||
| 245 | * @since 0.1.0 |
||
| 246 | */ |
||
| 247 | public function editName($title) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Archive the current pulse. |
||
| 260 | * |
||
| 261 | * This is the equivalent of a soft delete and can be restored from the DaPulse website. |
||
| 262 | * |
||
| 263 | * @api |
||
| 264 | * @since 0.1.0 |
||
| 265 | */ |
||
| 266 | public function archivePulse() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Delete the current Pulse |
||
| 278 | * |
||
| 279 | * @api |
||
| 280 | * @throws \allejo\DaPulse\Exceptions\InvalidObjectException |
||
| 281 | */ |
||
| 282 | View Code Duplication | public function deletePulse () |
|
| 292 | |||
| 293 | public function duplicatePulse ($groupId = NULL, $ownerId = NULL) |
||
| 311 | |||
| 312 | View Code Duplication | private function pulseInjection (&$result) |
|
| 321 | |||
| 322 | // ================================================================================================================ |
||
| 323 | // Column data functions |
||
| 324 | // ================================================================================================================ |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Access a pulse's specific column to either access their value or to modify the value. |
||
| 328 | * |
||
| 329 | * See the related functions to see the appropriate replacements. |
||
| 330 | * |
||
| 331 | * @todo This function only exists for legacy applications. Remove in 0.1.1 |
||
| 332 | * |
||
| 333 | * @api |
||
| 334 | * @deprecated 0.0.1 This function will be removed by 0.2.0. New stricter functions are available |
||
| 335 | * |
||
| 336 | * @param string $columnId The ID of the column to access. It's typically a slugified version of the column title |
||
| 337 | * |
||
| 338 | * @see Pulse::getStatusColumn() getColorColumn() |
||
| 339 | * @see Pulse::getDateColumn() getDateColumn() |
||
| 340 | * @see Pulse::getPersonColumn() getPersonColumn() |
||
| 341 | * @see Pulse::getTextColumn() getTextColumn() |
||
| 342 | * @since 0.1.0 |
||
| 343 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 344 | * by this library or the DaPulse API. |
||
| 345 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 346 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
||
| 347 | */ |
||
| 348 | public function getColumnValue ($columnId) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Access a color type column value belonging to this pulse in order to read it or modify. |
||
| 369 | * |
||
| 370 | * This function should only be used to access color type values; an exception will be thrown otherwise. |
||
| 371 | * |
||
| 372 | * @api |
||
| 373 | * |
||
| 374 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 375 | * |
||
| 376 | * @since 0.1.0 |
||
| 377 | * @throws InvalidColumnException The specified column is not a "color" type column |
||
| 378 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 379 | * by this library or the DaPulse API. |
||
| 380 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 381 | * @return PulseColumnStatusValue A column object with access to its contents |
||
| 382 | */ |
||
| 383 | public function getStatusColumn ($columnId) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Access a date type column value belonging to this pulse in order to read it or modify. |
||
| 390 | * |
||
| 391 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
| 392 | * |
||
| 393 | * @api |
||
| 394 | * |
||
| 395 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 396 | * |
||
| 397 | * @since 0.1.0 |
||
| 398 | * @throws InvalidColumnException The specified column is not a "date" type column |
||
| 399 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 400 | * by this library or the DaPulse API. |
||
| 401 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 402 | * @return PulseColumnDateValue A column object with access to its contents |
||
| 403 | */ |
||
| 404 | public function getDateColumn ($columnId) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Access a person type column value belonging to this pulse in order to read it or modify. |
||
| 411 | * |
||
| 412 | * This function should only be used to access person type values; an exception will be thrown otherwise. |
||
| 413 | * |
||
| 414 | * @api |
||
| 415 | * |
||
| 416 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 417 | * |
||
| 418 | * @since 0.1.0 |
||
| 419 | * @throws InvalidColumnException The specified column is not a "person" type column |
||
| 420 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 421 | * by this library or the DaPulse API. |
||
| 422 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 423 | * @return PulseColumnPersonValue A column object with access to its contents |
||
| 424 | */ |
||
| 425 | public function getPersonColumn ($columnId) |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Access a text type column value belonging to this pulse in order to read it or modify. |
||
| 432 | * |
||
| 433 | * This function should only be used to access text type values; an exception will be thrown otherwise. |
||
| 434 | * |
||
| 435 | * @api |
||
| 436 | * |
||
| 437 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 438 | * |
||
| 439 | * @since 0.1.0 |
||
| 440 | * @throws InvalidColumnException The specified column is not a "text" type column |
||
| 441 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 442 | * by this library or the DaPulse API. |
||
| 443 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 444 | * @return PulseColumnTextValue A column object with access to its contents |
||
| 445 | */ |
||
| 446 | public function getTextColumn ($columnId) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Build a pulse's column object if it doesn't exist or return the existing column. |
||
| 453 | * |
||
| 454 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column |
||
| 455 | * title |
||
| 456 | * @param string $columnType The type of column being accessed: 'text', 'color', 'person', or 'date' |
||
| 457 | * |
||
| 458 | * @since 0.1.0 |
||
| 459 | * |
||
| 460 | * @throws InvalidColumnException The specified column is not the same type as specified in `$columnType` |
||
| 461 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 462 | * by this library or the DaPulse API. |
||
| 463 | * @throws InvalidColumnException The specified column ID does not exist for this Pulse |
||
| 464 | * |
||
| 465 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
||
| 466 | */ |
||
| 467 | private function getColumn ($columnId, $columnType) |
||
| 517 | |||
| 518 | // ================================================================================================================ |
||
| 519 | // Notes functions |
||
| 520 | // ================================================================================================================ |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Create a new note in this project |
||
| 524 | * |
||
| 525 | * @api |
||
| 526 | * |
||
| 527 | * @param string $title The title of the note |
||
| 528 | * @param string $content The body of the note |
||
| 529 | * @param bool $ownersOnly Set to true if only pulse owners can edit this note. |
||
| 530 | * @param int|null $userId The id of the user to be marked as the note's last updater |
||
| 531 | * @param bool $createUpdate Indicates whether to create an update on the pulse notifying subscribers on the |
||
| 532 | * changes (required user_id to be set). |
||
| 533 | * |
||
| 534 | * @since 0.1.0 |
||
| 535 | * @return PulseNote |
||
| 536 | */ |
||
| 537 | public function addNote ($title, $content, $ownersOnly = false, $userId = NULL, $createUpdate = false) |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Return all of the notes belonging to this project |
||
| 562 | * |
||
| 563 | * @api |
||
| 564 | * @since 0.1.0 |
||
| 565 | * @return PulseNote[] |
||
| 566 | */ |
||
| 567 | public function getNotes () |
||
| 573 | |||
| 574 | // ================================================================================================================ |
||
| 575 | // Updates functions |
||
| 576 | // ================================================================================================================ |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Get all of the updates that belong this Pulse in reverse chronological order |
||
| 580 | * |
||
| 581 | * @api |
||
| 582 | * @since 0.1.0 |
||
| 583 | * @return PulseUpdate[] |
||
| 584 | */ |
||
| 585 | public function getUpdates () |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Create an update for the current Pulse |
||
| 594 | * |
||
| 595 | * @api |
||
| 596 | * |
||
| 597 | * @param int|PulseUser $user |
||
| 598 | * @param string $text |
||
| 599 | * @param null|bool $announceToAll |
||
| 600 | * |
||
| 601 | * @since 0.1.0 |
||
| 602 | */ |
||
| 603 | public function createUpdate ($user, $text, $announceToAll = NULL) |
||
| 607 | |||
| 608 | // ================================================================================================================ |
||
| 609 | // Static functions |
||
| 610 | // ================================================================================================================ |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Get all of the pulses that belong to the organization across all boards. |
||
| 614 | * |
||
| 615 | * To modify the amount of data returned with pagination, use the following values in the array to configure your |
||
| 616 | * pagination or offsets. |
||
| 617 | * |
||
| 618 | * ```php |
||
| 619 | * $params = array( |
||
| 620 | * "page" => 1, // (int) Page offset to fetch |
||
| 621 | * "per_page" => 10, // (int) Number of results per page |
||
| 622 | * "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
||
| 623 | * "order_by_latest" => true // (bool) Order the pulses with the most recent first |
||
| 624 | * ); |
||
| 625 | * ``` |
||
| 626 | * |
||
| 627 | * @api |
||
| 628 | * |
||
| 629 | * @param array $params GET parameters passed to with the query to modify the data returned. |
||
| 630 | * |
||
| 631 | * @since 0.1.0 |
||
| 632 | * @return Pulse[] |
||
| 633 | */ |
||
| 634 | public static function getPulses ($params = array()) |
||
| 640 | } |
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..