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 |
||
31 | class Pulse extends SubscribableObject |
||
32 | { |
||
33 | /** |
||
34 | * @ignore |
||
35 | */ |
||
36 | const API_PREFIX = "pulses"; |
||
37 | |||
38 | // ================================================================================================================ |
||
39 | // Instance Variables |
||
40 | // ================================================================================================================ |
||
41 | |||
42 | /** |
||
43 | * The resource's URL. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $url; |
||
48 | |||
49 | /** |
||
50 | * The pulse's name. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $name; |
||
55 | |||
56 | /** |
||
57 | * The amount of updates a pulse has. |
||
58 | * |
||
59 | * @var int |
||
60 | */ |
||
61 | protected $updates_count; |
||
62 | |||
63 | /** |
||
64 | * The ID of the parent board. |
||
65 | * |
||
66 | * @var int |
||
67 | */ |
||
68 | protected $board_id; |
||
69 | |||
70 | /** |
||
71 | * Creation time. |
||
72 | * |
||
73 | * @var \DateTime |
||
74 | */ |
||
75 | protected $created_at; |
||
76 | |||
77 | /** |
||
78 | * Last update time. |
||
79 | * |
||
80 | * @var \DateTime |
||
81 | */ |
||
82 | protected $updated_at; |
||
83 | |||
84 | /** |
||
85 | * The ID of the group this pulse belongs to |
||
86 | * |
||
87 | * @var string |
||
88 | */ |
||
89 | protected $group_id; |
||
90 | |||
91 | /** |
||
92 | * @var PulseColumn[] |
||
93 | */ |
||
94 | protected $column_structure; |
||
95 | |||
96 | /** |
||
97 | * An array containing all of the values a pulse has for each column |
||
98 | * |
||
99 | * @var mixed |
||
100 | */ |
||
101 | protected $raw_column_values; |
||
102 | |||
103 | /** |
||
104 | * An array containing objects extended from PulseColumnValue storing all of the values for each column |
||
105 | * |
||
106 | * @var array |
||
107 | */ |
||
108 | protected $column_values; |
||
109 | |||
110 | /** |
||
111 | * The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates |
||
112 | * |
||
113 | * @var string |
||
114 | */ |
||
115 | private $urlSyntax = "%s/%s/%s.json"; |
||
116 | |||
117 | // ================================================================================================================ |
||
118 | // Overloaded functions |
||
119 | // ================================================================================================================ |
||
120 | |||
121 | protected function initializeValues () |
||
127 | 70 | ||
128 | 70 | // ================================================================================================================ |
|
129 | // Getter functions |
||
130 | // ================================================================================================================ |
||
131 | |||
132 | /** |
||
133 | * The resource's URL. |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | public function getUrl () |
||
143 | |||
144 | /** |
||
145 | * The pulse's name. |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | 2 | public function getName () |
|
155 | |||
156 | /** |
||
157 | * The amount of updates a pulse has. |
||
158 | * |
||
159 | 1 | * @return int |
|
160 | */ |
||
161 | 1 | public function getUpdatesCount () |
|
167 | |||
168 | /** |
||
169 | 40 | * The ID of the parent board. |
|
170 | * |
||
171 | 40 | * @return int |
|
172 | */ |
||
173 | public function getBoardId () |
||
179 | 1 | ||
180 | /** |
||
181 | 1 | * Creation time. |
|
182 | * |
||
183 | 1 | * @return \DateTime |
|
184 | */ |
||
185 | public function getCreatedAt () |
||
192 | |||
193 | 1 | /** |
|
194 | * Last update time. |
||
195 | 1 | * |
|
196 | * @return \DateTime |
||
197 | */ |
||
198 | public function getUpdatedAt () |
||
205 | |||
206 | /** |
||
207 | * 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 |
||
208 | * find the group ID via brute force. |
||
209 | * |
||
210 | * **Note** The group ID is cached if it is not available. To update the cached value, use $forceFetch to force an |
||
211 | * API call to get a new value. |
||
212 | 1 | * |
|
213 | * **Warning** An API call is always slower than using the cached value. |
||
214 | 1 | * |
|
215 | * @param bool $forceFetch Force an API call to get an updated group ID if it has been changed |
||
216 | 1 | * |
|
217 | 1 | * @since 0.1.0 |
|
218 | * @return string |
||
219 | 1 | */ |
|
220 | public function getGroupId ($forceFetch = false) |
||
241 | |||
242 | // ================================================================================================================ |
||
243 | // Pulse functions |
||
244 | // ================================================================================================================ |
||
245 | |||
246 | /** |
||
247 | * Edit the name of the pulse |
||
248 | * |
||
249 | * @api |
||
250 | * @param string $title |
||
251 | * @since 0.1.0 |
||
252 | */ |
||
253 | public function editName($title) |
||
263 | |||
264 | /** |
||
265 | * Archive the current pulse |
||
266 | * |
||
267 | * This is the equivalent of a soft delete and can be restored from the DaPulse website. |
||
268 | * |
||
269 | * @api |
||
270 | * @since 0.1.0 |
||
271 | */ |
||
272 | public function archivePulse () |
||
282 | |||
283 | /** |
||
284 | * Delete the current Pulse |
||
285 | * |
||
286 | * @api |
||
287 | * @since 0.1.0 |
||
288 | * @throws \allejo\DaPulse\Exceptions\InvalidObjectException |
||
289 | */ |
||
290 | View Code Duplication | public function deletePulse () |
|
300 | |||
301 | public function duplicatePulse ($groupId = NULL, $ownerId = NULL) |
||
319 | |||
320 | View Code Duplication | private function pulseInjection (&$result) |
|
329 | |||
330 | // ================================================================================================================ |
||
331 | // Column data functions |
||
332 | // ================================================================================================================ |
||
333 | |||
334 | /** |
||
335 | * Access a color type column value belonging to this pulse in order to read it or modify. |
||
336 | * |
||
337 | * This function should only be used to access color type values; an exception will be thrown otherwise. |
||
338 | * |
||
339 | * @api |
||
340 | 6 | * |
|
341 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
342 | 6 | * |
|
343 | * @since 0.1.0 |
||
344 | * |
||
345 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
346 | * @throws InvalidColumnException The specified column is not a "color" type column |
||
347 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
348 | * by this library or the DaPulse API. |
||
349 | * |
||
350 | * @return PulseColumnStatusValue A column object with access to its contents |
||
351 | */ |
||
352 | public function getStatusColumn ($columnId) |
||
356 | |||
357 | /** |
||
358 | * Access a date type column value belonging to this pulse in order to read it or modify. |
||
359 | * |
||
360 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
361 | * |
||
362 | * @api |
||
363 | 9 | * |
|
364 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
365 | 9 | * |
|
366 | * @since 0.1.0 |
||
367 | * |
||
368 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
369 | * @throws InvalidColumnException The specified column is not a "date" type column |
||
370 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
371 | * by this library or the DaPulse API. |
||
372 | * |
||
373 | * @return PulseColumnDateValue A column object with access to its contents |
||
374 | */ |
||
375 | public function getDateColumn ($columnId) |
||
379 | |||
380 | /** |
||
381 | * Access a numeric type column value belonging to this pulse in order to read it or modify. |
||
382 | * |
||
383 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
384 | * |
||
385 | * @api |
||
386 | 7 | * |
|
387 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
388 | 7 | * |
|
389 | * @since 0.2.0 |
||
390 | * |
||
391 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
392 | * @throws InvalidColumnException The specified column is not a "numeric" type column |
||
393 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
394 | * by this library or the DaPulse API. |
||
395 | * |
||
396 | * @return PulseColumnNumericValue A column object with access to its contents |
||
397 | */ |
||
398 | public function getNumericColumn ($columnId) |
||
402 | |||
403 | /** |
||
404 | * Access a person type column value belonging to this pulse in order to read it or modify. |
||
405 | * |
||
406 | * This function should only be used to access person type values; an exception will be thrown otherwise. |
||
407 | * |
||
408 | * @api |
||
409 | 9 | * |
|
410 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
411 | 9 | * |
|
412 | * @since 0.1.0 |
||
413 | * |
||
414 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
415 | * @throws InvalidColumnException The specified column is not a "person" type column |
||
416 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
417 | * by this library or the DaPulse API. |
||
418 | * |
||
419 | * @return PulseColumnPersonValue A column object with access to its contents |
||
420 | */ |
||
421 | public function getPersonColumn ($columnId) |
||
425 | |||
426 | /** |
||
427 | * Access a text type column value belonging to this pulse in order to read it or modify. |
||
428 | * |
||
429 | * This function should only be used to access text type values; an exception will be thrown otherwise. |
||
430 | * |
||
431 | * @api |
||
432 | 4 | * |
|
433 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
434 | 4 | * |
|
435 | * @since 0.1.0 |
||
436 | |||
437 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
438 | * @throws InvalidColumnException The specified column is not a "text" type column |
||
439 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
440 | * by this library or the DaPulse API. |
||
441 | * |
||
442 | * @return PulseColumnTextValue A column object with access to its contents |
||
443 | */ |
||
444 | public function getTextColumn ($columnId) |
||
448 | |||
449 | /** |
||
450 | * Access a timeline type column value belonging to this pulse in order to read it or modify. |
||
451 | * |
||
452 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
453 | * |
||
454 | * @api |
||
455 | 5 | * |
|
456 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
457 | 5 | * |
|
458 | * @since 0.2.1 |
||
459 | * |
||
460 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
461 | * @throws InvalidColumnException The specified column is not a "numeric" type column |
||
462 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
463 | * by this library or the DaPulse API. |
||
464 | * |
||
465 | * @return PulseColumnTimelineValue A column object with access to its contents |
||
466 | */ |
||
467 | public function getTimelineColumn ($columnId) |
||
471 | |||
472 | /** |
||
473 | * Build a pulse's column object if it doesn't exist or return the existing column. |
||
474 | * |
||
475 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column |
||
476 | 40 | * title |
|
477 | * @param string $columnType The type of column being accessed: 'text', 'color', 'person', 'numeric', or 'date' |
||
478 | 40 | * |
|
479 | * @since 0.1.0 |
||
480 | 40 | * |
|
481 | 40 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
|
482 | * @throws InvalidColumnException The specified column is not the same type as specified in `$columnType` |
||
483 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
484 | * by this library or the DaPulse API. |
||
485 | * |
||
486 | 40 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
|
487 | */ |
||
488 | 29 | private function getColumn ($columnId, $columnType) |
|
538 | |||
539 | // ================================================================================================================ |
||
540 | // Notes functions |
||
541 | // ================================================================================================================ |
||
542 | |||
543 | /** |
||
544 | * Create a new note in this project |
||
545 | * |
||
546 | * @api |
||
547 | * |
||
548 | * @param string $title The title of the note |
||
549 | * @param string $content The body of the note |
||
550 | * @param bool $ownersOnly Set to true if only pulse owners can edit this note. |
||
551 | * @param int|null $userId The id of the user to be marked as the note's last updater |
||
552 | * @param bool $createUpdate Indicates whether to create an update on the pulse notifying subscribers on the |
||
553 | * changes (required user_id to be set). |
||
554 | * |
||
555 | * @since 0.1.0 |
||
556 | * @return PulseNote |
||
557 | */ |
||
558 | public function addNote ($title, $content, $ownersOnly = false, $userId = NULL, $createUpdate = false) |
||
580 | |||
581 | /** |
||
582 | * Return all of the notes belonging to this project |
||
583 | * |
||
584 | * @api |
||
585 | * @since 0.1.0 |
||
586 | * @return PulseNote[] |
||
587 | */ |
||
588 | public function getNotes () |
||
594 | |||
595 | // ================================================================================================================ |
||
596 | 20 | // Updates functions |
|
597 | // ================================================================================================================ |
||
598 | 20 | ||
599 | /** |
||
600 | 20 | * Get all of the updates that belong to this Pulse in reverse chronological order |
|
601 | * |
||
602 | * @api |
||
603 | * |
||
604 | * @since 0.1.0 |
||
605 | * |
||
606 | * @return PulseUpdate[] |
||
607 | */ |
||
608 | public function getUpdates () |
||
614 | |||
615 | /** |
||
616 | * Create an update for the current Pulse |
||
617 | * |
||
618 | * @api |
||
619 | * |
||
620 | * @param int|PulseUser $user |
||
621 | * @param string $text |
||
622 | * @param null|bool $announceToAll |
||
623 | * |
||
624 | * @since 0.2.2 A PulseUpdate object is returned containing the information of the newly created Update |
||
625 | * @since 0.1.0 |
||
626 | * |
||
627 | * @return PulseUpdate |
||
628 | */ |
||
629 | public function createUpdate ($user, $text, $announceToAll = NULL) |
||
633 | |||
634 | // ================================================================================================================ |
||
635 | // Static functions |
||
636 | // ================================================================================================================ |
||
637 | |||
638 | /** |
||
639 | * Get all of the pulses that belong to the organization across all boards. |
||
640 | * |
||
641 | * To modify the amount of data returned with pagination, use the following values in the array to configure your |
||
642 | * pagination or offsets. |
||
643 | * |
||
644 | * ```php |
||
645 | * $params = array( |
||
646 | * "page" => 1, // (int) Page offset to fetch |
||
647 | * "per_page" => 10, // (int) Number of results per page |
||
648 | * "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
||
649 | * "order_by_latest" => true // (bool) Order the pulses with the most recent first |
||
650 | * ); |
||
651 | * ``` |
||
652 | * |
||
653 | * @api |
||
654 | * |
||
655 | * @param array $params GET parameters passed to with the query to modify the data returned. |
||
656 | * |
||
657 | * @since 0.1.0 |
||
658 | * @return Pulse[] |
||
659 | */ |
||
660 | public static function getPulses ($params = array()) |
||
666 | } |
||
667 |
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..