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 |
||
33 | class Pulse extends SubscribableObject |
||
34 | { |
||
35 | /** |
||
36 | * @ignore |
||
37 | */ |
||
38 | const API_PREFIX = "pulses"; |
||
39 | |||
40 | // ================================================================================================================ |
||
41 | // Instance Variables |
||
42 | // ================================================================================================================ |
||
43 | |||
44 | /** |
||
45 | * The resource's URL. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $url; |
||
50 | |||
51 | /** |
||
52 | * The pulse's name. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $name; |
||
57 | |||
58 | /** |
||
59 | * The amount of updates a pulse has. |
||
60 | * |
||
61 | * @var int |
||
62 | */ |
||
63 | protected $updates_count; |
||
64 | |||
65 | /** |
||
66 | * The ID of the parent board. |
||
67 | * |
||
68 | * @var int |
||
69 | */ |
||
70 | protected $board_id; |
||
71 | |||
72 | /** |
||
73 | * Creation time. |
||
74 | * |
||
75 | * @var \DateTime |
||
76 | */ |
||
77 | protected $created_at; |
||
78 | |||
79 | /** |
||
80 | * Last update time. |
||
81 | * |
||
82 | * @var \DateTime |
||
83 | */ |
||
84 | protected $updated_at; |
||
85 | |||
86 | /** |
||
87 | * The ID of the group this pulse belongs to |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $group_id; |
||
92 | |||
93 | /** |
||
94 | * @var PulseColumn[] |
||
95 | */ |
||
96 | protected $column_structure; |
||
97 | |||
98 | /** |
||
99 | * An array containing all of the values a pulse has for each column |
||
100 | * |
||
101 | * @var mixed |
||
102 | */ |
||
103 | protected $raw_column_values; |
||
104 | |||
105 | /** |
||
106 | * An array containing objects extended from PulseColumnValue storing all of the values for each column |
||
107 | * |
||
108 | * @var array |
||
109 | */ |
||
110 | protected $column_values; |
||
111 | |||
112 | /** |
||
113 | * The common URL path for retrieving objects relating a pulse such as subscribers, notes, or updates |
||
114 | * |
||
115 | * @var string |
||
116 | */ |
||
117 | private $urlSyntax = "%s/%s/%s.json"; |
||
118 | |||
119 | // ================================================================================================================ |
||
120 | // Overloaded functions |
||
121 | // ================================================================================================================ |
||
122 | |||
123 | 70 | protected function initializeValues () |
|
129 | |||
130 | // ================================================================================================================ |
||
131 | // Getter functions |
||
132 | // ================================================================================================================ |
||
133 | |||
134 | /** |
||
135 | * The resource's URL. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | 1 | public function getUrl () |
|
143 | |||
144 | /** |
||
145 | * The pulse's name. |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | 2 | public function getName () |
|
153 | |||
154 | /** |
||
155 | * The amount of updates a pulse has. |
||
156 | * |
||
157 | * @return int |
||
158 | */ |
||
159 | 1 | public function getUpdatesCount () |
|
163 | |||
164 | /** |
||
165 | * The ID of the parent board. |
||
166 | * |
||
167 | * @return int |
||
168 | */ |
||
169 | 40 | public function getBoardId () |
|
173 | |||
174 | /** |
||
175 | * Creation time. |
||
176 | * |
||
177 | * @return \DateTime |
||
178 | */ |
||
179 | 1 | public function getCreatedAt () |
|
185 | |||
186 | /** |
||
187 | * Last update time. |
||
188 | * |
||
189 | * @return \DateTime |
||
190 | */ |
||
191 | 1 | public function getUpdatedAt () |
|
197 | |||
198 | /** |
||
199 | * 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 |
||
200 | * find the group ID via brute force. |
||
201 | * |
||
202 | * **Note** The group ID is cached if it is not available. To update the cached value, use $forceFetch to force an |
||
203 | * API call to get a new value. |
||
204 | * |
||
205 | * **Warning** An API call is always slower than using the cached value. |
||
206 | * |
||
207 | * @param bool $forceFetch Force an API call to get an updated group ID if it has been changed |
||
208 | * |
||
209 | * @since 0.1.0 |
||
210 | * @return string |
||
211 | */ |
||
212 | 1 | public function getGroupId ($forceFetch = false) |
|
231 | |||
232 | // ================================================================================================================ |
||
233 | // Pulse functions |
||
234 | // ================================================================================================================ |
||
235 | |||
236 | private static function editPulseNameCall ($pulseID, $newName) |
||
245 | |||
246 | /** |
||
247 | * Edit the name of a Pulse |
||
248 | * |
||
249 | * **Tip:** If you do not already have a Pulse object created or given to you, calling this function makes one less |
||
250 | * API call than creating a Pulse object and then calling `editName()` on that instance. |
||
251 | * |
||
252 | * @param int $pulseID |
||
253 | * @param string $newName |
||
254 | * |
||
255 | * @since 0.3.0 |
||
256 | * |
||
257 | * @return Pulse |
||
258 | */ |
||
259 | public static function editPulseName ($pulseID, $newName) |
||
265 | |||
266 | /** |
||
267 | * Edit the name of the pulse |
||
268 | * |
||
269 | * **Tip:** Calling `Pulse::editPulseName()` makes one less API call than creating a Pulse object. You should only |
||
270 | * call this function if you already have a Pulse instance created for other purposes or it has been given to you. |
||
271 | * |
||
272 | * @api |
||
273 | * @param string $title |
||
274 | * @since 0.1.0 |
||
275 | */ |
||
276 | public function editName($title) |
||
281 | |||
282 | /** |
||
283 | * Archive the current pulse. |
||
284 | * |
||
285 | * This is the equivalent of a soft delete and can be restored from the DaPulse website. |
||
286 | * |
||
287 | * @api |
||
288 | * @since 0.1.0 |
||
289 | */ |
||
290 | public function archivePulse() |
||
300 | |||
301 | /** |
||
302 | * Delete the current Pulse |
||
303 | * |
||
304 | * @api |
||
305 | * @throws \allejo\DaPulse\Exceptions\InvalidObjectException |
||
306 | */ |
||
307 | View Code Duplication | public function deletePulse () |
|
317 | |||
318 | public function duplicatePulse ($groupId = NULL, $ownerId = NULL) |
||
336 | |||
337 | View Code Duplication | private function pulseInjection (&$result) |
|
346 | |||
347 | // ================================================================================================================ |
||
348 | // Column data functions |
||
349 | // ================================================================================================================ |
||
350 | |||
351 | /** |
||
352 | * Access a color type column value belonging to this pulse in order to read it or modify. |
||
353 | * |
||
354 | * This function should only be used to access color type values; an exception will be thrown otherwise. |
||
355 | * |
||
356 | * @api |
||
357 | * |
||
358 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
359 | * |
||
360 | * @since 0.1.0 |
||
361 | * |
||
362 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
363 | 9 | * @throws InvalidColumnException The specified column is not a "color" type column |
|
364 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
365 | 9 | * by this library or the DaPulse API. |
|
366 | * |
||
367 | * @return PulseColumnStatusValue A column object with access to its contents |
||
368 | */ |
||
369 | public function getStatusColumn ($columnId) |
||
373 | |||
374 | /** |
||
375 | * Access a date type column value belonging to this pulse in order to read it or modify. |
||
376 | * |
||
377 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
378 | * |
||
379 | * @api |
||
380 | * |
||
381 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
382 | * |
||
383 | * @since 0.1.0 |
||
384 | * |
||
385 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
386 | 7 | * @throws InvalidColumnException The specified column is not a "date" type column |
|
387 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
388 | 7 | * by this library or the DaPulse API. |
|
389 | * |
||
390 | * @return PulseColumnDateValue A column object with access to its contents |
||
391 | */ |
||
392 | public function getDateColumn ($columnId) |
||
396 | |||
397 | /** |
||
398 | * Access a numeric type column value belonging to this pulse in order to read it or modify. |
||
399 | * |
||
400 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
401 | * |
||
402 | * @api |
||
403 | * |
||
404 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
405 | * |
||
406 | * @since 0.2.0 |
||
407 | * |
||
408 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
409 | 9 | * @throws InvalidColumnException The specified column is not a "numeric" type column |
|
410 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
411 | 9 | * by this library or the DaPulse API. |
|
412 | * |
||
413 | * @return PulseColumnNumericValue A column object with access to its contents |
||
414 | */ |
||
415 | public function getNumericColumn ($columnId) |
||
419 | |||
420 | /** |
||
421 | * Access a person type column value belonging to this pulse in order to read it or modify. |
||
422 | * |
||
423 | * This function should only be used to access person type values; an exception will be thrown otherwise. |
||
424 | * |
||
425 | * @api |
||
426 | * |
||
427 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
428 | * |
||
429 | * @since 0.1.0 |
||
430 | * |
||
431 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
432 | 4 | * @throws InvalidColumnException The specified column is not a "person" type column |
|
433 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
434 | 4 | * by this library or the DaPulse API. |
|
435 | * |
||
436 | * @return PulseColumnPersonValue A column object with access to its contents |
||
437 | */ |
||
438 | public function getPersonColumn ($columnId) |
||
442 | |||
443 | /** |
||
444 | * Access a text type column value belonging to this pulse in order to read it or modify. |
||
445 | * |
||
446 | * This function should only be used to access text type values; an exception will be thrown otherwise. |
||
447 | * |
||
448 | * @api |
||
449 | * |
||
450 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
451 | * |
||
452 | * @since 0.1.0 |
||
453 | |||
454 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
455 | 5 | * @throws InvalidColumnException The specified column is not a "text" type column |
|
456 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
457 | 5 | * by this library or the DaPulse API. |
|
458 | * |
||
459 | * @return PulseColumnTextValue A column object with access to its contents |
||
460 | */ |
||
461 | public function getTextColumn ($columnId) |
||
465 | |||
466 | /** |
||
467 | * Access a timeline type column value belonging to this pulse in order to read it or modify. |
||
468 | * |
||
469 | * This function should only be used to access data type values; an exception will be thrown otherwise. |
||
470 | * |
||
471 | * @api |
||
472 | * |
||
473 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column name |
||
474 | * |
||
475 | * @since 0.2.1 |
||
476 | 40 | * |
|
477 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
478 | 40 | * @throws InvalidColumnException The specified column is not a "numeric" type column |
|
479 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
480 | 40 | * by this library or the DaPulse API. |
|
481 | 40 | * |
|
482 | * @return PulseColumnTimelineValue A column object with access to its contents |
||
483 | */ |
||
484 | public function getTimelineColumn ($columnId) |
||
488 | 29 | ||
489 | /** |
||
490 | 29 | * Build a pulse's column object if it doesn't exist or return the existing column. |
|
491 | * |
||
492 | * @param string $columnId The ID of the column to access. This is typically a slugified version of the column |
||
493 | * title |
||
494 | * @param string $columnType The type of column being accessed: 'text', 'color', 'person', 'numeric', or 'date' |
||
495 | 29 | * |
|
496 | * @since 0.1.0 |
||
497 | 1 | * |
|
498 | * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse |
||
499 | 1 | * @throws InvalidColumnException The specified column is not the same type as specified in `$columnType` |
|
500 | * @throws InvalidObjectException The specified column exists but modification of its value is unsupported either |
||
501 | * by this library or the DaPulse API. |
||
502 | * |
||
503 | * @return PulseColumnValue The returned object will be a child of this abstract class. |
||
504 | 28 | */ |
|
505 | private function getColumn ($columnId, $columnType) |
||
555 | |||
556 | // ================================================================================================================ |
||
557 | // Notes functions |
||
558 | // ================================================================================================================ |
||
559 | |||
560 | /** |
||
561 | * Create a new note in this project |
||
562 | * |
||
563 | * @api |
||
564 | * |
||
565 | * @param string $title The title of the note |
||
566 | * @param string $content The body of the note |
||
567 | * @param bool $ownersOnly Set to true if only pulse owners can edit this note. |
||
568 | * @param int|null $userId The id of the user to be marked as the note's last updater |
||
569 | * @param bool $createUpdate Indicates whether to create an update on the pulse notifying subscribers on the |
||
570 | * changes (required user_id to be set). |
||
571 | * |
||
572 | * @since 0.1.0 |
||
573 | * @return PulseNote |
||
574 | */ |
||
575 | public function addNote ($title, $content, $ownersOnly = false, $userId = NULL, $createUpdate = false) |
||
597 | |||
598 | 20 | /** |
|
599 | * Return all of the notes belonging to this project |
||
600 | 20 | * |
|
601 | * @api |
||
602 | * @since 0.1.0 |
||
603 | * @return PulseNote[] |
||
604 | */ |
||
605 | public function getNotes () |
||
611 | |||
612 | // ================================================================================================================ |
||
613 | // Updates functions |
||
614 | // ================================================================================================================ |
||
615 | |||
616 | /** |
||
617 | * Get all of the updates that belong to this Pulse in reverse chronological order |
||
618 | * |
||
619 | * @api |
||
620 | * |
||
621 | * @since 0.1.0 |
||
622 | * |
||
623 | * @return PulseUpdate[] |
||
624 | */ |
||
625 | public function getUpdates () |
||
631 | |||
632 | /** |
||
633 | * Create an update for the current Pulse |
||
634 | * |
||
635 | * @api |
||
636 | * |
||
637 | * @param int|PulseUser $user |
||
638 | * @param string $text |
||
639 | * @param null|bool $announceToAll |
||
640 | * |
||
641 | * @since 0.2.2 A PulseUpdate object is returned containing the information of the newly created Update |
||
642 | * @since 0.1.0 |
||
643 | * |
||
644 | * @return PulseUpdate |
||
645 | */ |
||
646 | public function createUpdate ($user, $text, $announceToAll = NULL) |
||
650 | |||
651 | // ================================================================================================================ |
||
652 | // Static functions |
||
653 | // ================================================================================================================ |
||
654 | |||
655 | /** |
||
656 | * Get all of the pulses that belong to the organization across all boards. |
||
657 | * |
||
658 | * To modify the amount of data returned with pagination, use the following values in the array to configure your |
||
659 | * pagination or offsets. |
||
660 | * |
||
661 | * ```php |
||
662 | * $params = array( |
||
663 | * "page" => 1, // (int) Page offset to fetch |
||
664 | * "per_page" => 10, // (int) Number of results per page |
||
665 | * "offset" => 5, // (int) Instead of starting at result 0, start counting from result 5 |
||
666 | * "order_by_latest" => true // (bool) Order the pulses with the most recent first |
||
667 | * ); |
||
668 | * ``` |
||
669 | * |
||
670 | * @api |
||
671 | * |
||
672 | * @param array $params GET parameters passed to with the query to modify the data returned. |
||
673 | * |
||
674 | * @since 0.1.0 |
||
675 | * @return Pulse[] |
||
676 | */ |
||
677 | public static function getPulses ($params = array()) |
||
683 | } |
||
684 |
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..