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 ApiObject |
||
| 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 unique identifier. |
||
| 50 | * |
||
| 51 | * @var int |
||
| 52 | */ |
||
| 53 | protected $id; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The pulse's name. |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $name; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The board's subscribers. |
||
| 64 | * |
||
| 65 | * @var PulseUser[] |
||
| 66 | */ |
||
| 67 | protected $subscribers; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The amount of updates a pulse has. |
||
| 71 | * |
||
| 72 | * @var int |
||
| 73 | */ |
||
| 74 | protected $updates_count; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The ID of the parent board. |
||
| 78 | * |
||
| 79 | * @var int |
||
| 80 | */ |
||
| 81 | protected $board_id; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Creation time. |
||
| 85 | * |
||
| 86 | * @var \DateTime |
||
| 87 | */ |
||
| 88 | protected $created_at; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Last update time. |
||
| 92 | * |
||
| 93 | * @var \DateTime |
||
| 94 | */ |
||
| 95 | protected $updated_at; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * The ID of the group this pulse belongs to |
||
| 99 | * |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $group_id; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var PulseColumn[] |
||
| 106 | */ |
||
| 107 | protected $column_structure; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * An array containing all of the values a pulse has for each column |
||
| 111 | * |
||
| 112 | * @var mixed |
||
| 113 | */ |
||
| 114 | protected $raw_column_values; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * An array containing objects extended from PulseColumnValue storing all of the values for each column |
||
| 118 | * |
||
| 119 | * @var array |
||
| 120 | */ |
||
| 121 | protected $column_values; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates |
||
| 125 | * |
||
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | private $urlSyntax = "%s/%s/%s.json"; |
||
| 129 | |||
| 130 | // ================================================================================================================ |
||
| 131 | // Getter functions |
||
| 132 | // ================================================================================================================ |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The resource's URL. |
||
| 136 | * |
||
| 137 | * @return string |
||
| 138 | */ |
||
| 139 | public function getUrl() |
||
| 143 | |||
| 144 | /** |
||
| 145 | * The pulse's unique identifier. |
||
| 146 | * |
||
| 147 | * @return int |
||
| 148 | */ |
||
| 149 | public function getId() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * The pulse's name. |
||
| 156 | * |
||
| 157 | * @return string |
||
| 158 | */ |
||
| 159 | public function getName() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * The amount of updates a pulse has. |
||
| 166 | * |
||
| 167 | * @return int |
||
| 168 | */ |
||
| 169 | public function getUpdatesCount() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * The ID of the parent board. |
||
| 176 | * |
||
| 177 | * @return int |
||
| 178 | */ |
||
| 179 | public function getBoardId() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Creation time. |
||
| 186 | * |
||
| 187 | * @return \DateTime |
||
| 188 | */ |
||
| 189 | public function getCreatedAt() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Last update time. |
||
| 196 | * |
||
| 197 | * @return \DateTime |
||
| 198 | */ |
||
| 199 | public function getUpdatedAt() |
||
| 203 | |||
| 204 | // ================================================================================================================ |
||
| 205 | // Pulse functions |
||
| 206 | // ================================================================================================================ |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Delete the current Pulse |
||
| 210 | * |
||
| 211 | * @api |
||
| 212 | * @throws \allejo\DaPulse\Exceptions\InvalidObjectException |
||
| 213 | */ |
||
| 214 | View Code Duplication | public function deletePulse () |
|
| 224 | |||
| 225 | public function duplicatePulse ($group_id = null, $owner_id = null) |
||
| 243 | |||
| 244 | View Code Duplication | private function pulseInjection (&$result) |
|
| 253 | |||
| 254 | // ================================================================================================================ |
||
| 255 | // Column data functions |
||
| 256 | // ================================================================================================================ |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Access a pulse's specific column to either access their value or to modify the value. |
||
| 260 | * |
||
| 261 | * See the related functions to see the appropriate replacements. |
||
| 262 | * |
||
| 263 | * @todo This function only exists for legacy applications. Remove in 0.1.1 |
||
| 264 | * |
||
| 265 | * @api |
||
| 266 | * @deprecated 0.0.1 This function will be removed by 0.1.1. New stricter functions are available |
||
| 267 | * @param string $columnId The ID of the column to access. It's typically a slugified version of the column title |
||
| 268 | * @see Pulse::getColorColumn() getColorColumn() |
||
| 269 | * @see Pulse::getDateColumn() getDateColumn() |
||
| 270 | * @see Pulse::getPersonColumn() getPersonColumn() |
||
| 271 | * @see Pulse::getTextColumn() getTextColumn() |
||
| 272 | * @since 0.1.0 |
||
| 273 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 274 | * by this library or the DaPulse API. |
||
| 275 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 276 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
||
| 277 | */ |
||
| 278 | public function getColumnValue ($columnId) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Access a color type column value belonging to this pulse in order to read it or modify. |
||
| 299 | * |
||
| 300 | * This function should only be used to access color type values; an exception will be thrown otherwise. |
||
| 301 | * |
||
| 302 | * @api |
||
| 303 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 304 | * @since 0.1.0 |
||
| 305 | * @throws InvalidColumnException The specified column is not a "color" type column |
||
| 306 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 307 | * by this library or the DaPulse API. |
||
| 308 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 309 | * @return PulseColumnColorValue A column object with access to its contents |
||
| 310 | */ |
||
| 311 | public function getColorColumn ($columnId) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Access a date type column value belonging to this pulse in order to read it or modify. |
||
| 318 | * |
||
| 319 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
| 320 | * |
||
| 321 | * @api |
||
| 322 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 323 | * @since 0.1.0 |
||
| 324 | * @throws InvalidColumnException The specified column is not a "date" type column |
||
| 325 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 326 | * by this library or the DaPulse API. |
||
| 327 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 328 | * @return PulseColumnDateValue A column object with access to its contents |
||
| 329 | */ |
||
| 330 | public function getDateColumn ($columnId) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Access a person type column value belonging to this pulse in order to read it or modify. |
||
| 337 | * |
||
| 338 | * This function should only be used to access person type values; an exception will be thrown otherwise. |
||
| 339 | * |
||
| 340 | * @api |
||
| 341 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 342 | * @since 0.1.0 |
||
| 343 | * @throws InvalidColumnException The specified column is not a "person" type column |
||
| 344 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 345 | * by this library or the DaPulse API. |
||
| 346 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 347 | * @return PulseColumnPersonValue A column object with access to its contents |
||
| 348 | */ |
||
| 349 | public function getPersonColumn ($columnId) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Access a text type column value belonging to this pulse in order to read it or modify. |
||
| 356 | * |
||
| 357 | * This function should only be used to access text type values; an exception will be thrown otherwise. |
||
| 358 | * |
||
| 359 | * @api |
||
| 360 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
| 361 | * @since 0.1.0 |
||
| 362 | * @throws InvalidColumnException The specified column is not a "text" type column |
||
| 363 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 364 | * by this library or the DaPulse API. |
||
| 365 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 366 | * @return PulseColumnTextValue A column object with access to its contents |
||
| 367 | */ |
||
| 368 | public function getTextColumn ($columnId) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Build a pulse's column object if it doesn't exist or return the existing column. |
||
| 375 | * |
||
| 376 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column |
||
| 377 | * title |
||
| 378 | * @param string $columnType The type of column being accessed: 'text', 'color', 'person', or 'date' |
||
| 379 | * |
||
| 380 | * @since 0.1.0 |
||
| 381 | * |
||
| 382 | * @throws InvalidColumnException The specified column is not the same type as specified in `$columnType` |
||
| 383 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
| 384 | * by this library or the DaPulse API. |
||
| 385 | * @throws KeyNotFoundException The specified column ID does not exist for this Pulse |
||
| 386 | * |
||
| 387 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
||
| 388 | */ |
||
| 389 | private function getColumn ($columnId, $columnType) |
||
| 412 | |||
| 413 | // ================================================================================================================ |
||
| 414 | // Subscribers functions |
||
| 415 | // ================================================================================================================ |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Access a pulse's subscribers |
||
| 419 | * |
||
| 420 | * To modify the amount of data returned with pagination, use the following values in the array to configure your |
||
| 421 | * pagination or offsets. |
||
| 422 | * |
||
| 423 | * ```php |
||
| 424 | * $params = array( |
||
| 425 | * "page" => 1, // (int) Page offset to fetch |
||
| 426 | * "per_page" => 10, // (int) Number of results per page |
||
| 427 | * "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
||
| 428 | * ); |
||
| 429 | * ``` |
||
| 430 | * |
||
| 431 | * @api |
||
| 432 | * @param array $params GET parameters passed to with the query to modify the data returned. |
||
| 433 | * @since 0.1.0 |
||
| 434 | * @return PulseUser[] |
||
| 435 | */ |
||
| 436 | public function getSubscribers ($params = array()) |
||
| 442 | |||
| 443 | // ================================================================================================================ |
||
| 444 | // Notes functions |
||
| 445 | // ================================================================================================================ |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Create a new note in this project |
||
| 449 | * |
||
| 450 | * @api |
||
| 451 | * @param string $title The title of the note |
||
| 452 | * @param string $content The body of the note |
||
| 453 | * @param bool $owners_only Set to true if only pulse owners can edit this note. |
||
| 454 | * @param int|null $user_id The id of the user to be marked as the note’s last updater |
||
| 455 | * @param bool $create_update Indicates whether to create an update on the pulse notifying subscribers on the |
||
| 456 | * changes (required user_id to be set). |
||
| 457 | * @since 0.1.0 |
||
| 458 | * @return PulseNote |
||
| 459 | */ |
||
| 460 | public function addNote ($title, $content, $owners_only = false, $user_id = NULL, $create_update = false) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return all of the notes belonging to this project |
||
| 485 | * |
||
| 486 | * @api |
||
| 487 | * @since 0.1.0 |
||
| 488 | * @return PulseNote[] |
||
| 489 | */ |
||
| 490 | public function getNotes () |
||
| 496 | |||
| 497 | // ================================================================================================================ |
||
| 498 | // Updates functions |
||
| 499 | // ================================================================================================================ |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Get all of the updates that belong this Pulse |
||
| 503 | * |
||
| 504 | * @api |
||
| 505 | * @since 0.1.0 |
||
| 506 | * @return PulseUpdate[] |
||
| 507 | */ |
||
| 508 | public function getUpdates () |
||
| 514 | |||
| 515 | // ================================================================================================================ |
||
| 516 | // Static functions |
||
| 517 | // ================================================================================================================ |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Get all of the pulses that belong to the organization across all boards. |
||
| 521 | * |
||
| 522 | * To modify the amount of data returned with pagination, use the following values in the array to configure your |
||
| 523 | * pagination or offsets. |
||
| 524 | * |
||
| 525 | * ```php |
||
| 526 | * $params = array( |
||
| 527 | * "page" => 1, // (int) Page offset to fetch |
||
| 528 | * "per_page" => 10, // (int) Number of results per page |
||
| 529 | * "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
||
| 530 | * "order_by_latest" => true // (bool) Order the pulses with the most recent first |
||
| 531 | * ); |
||
| 532 | * ``` |
||
| 533 | * |
||
| 534 | * @api |
||
| 535 | * @param array $params GET parameters passed to with the query to modify the data returned. |
||
| 536 | * @since 0.1.0 |
||
| 537 | * @return Pulse[] |
||
| 538 | */ |
||
| 539 | public static function getPulses ($params = array()) |
||
| 545 | } |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.