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 unique identifier. |
||
| 45 | * |
||
| 46 | * @var int |
||
| 47 | */ |
||
| 48 | protected $id; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The board's name. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $name; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The board's description. |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $description; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The board's visible columns. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected $columns; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Creation time. |
||
| 73 | * |
||
| 74 | * @var \DateTime |
||
| 75 | */ |
||
| 76 | protected $created_at; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Last update time. |
||
| 80 | * |
||
| 81 | * @var \DateTime |
||
| 82 | */ |
||
| 83 | protected $updated_at; |
||
| 84 | |||
| 85 | // ================================================================================================================= |
||
| 86 | // Getter functions |
||
| 87 | // ================================================================================================================= |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The resource's URL. |
||
| 91 | * |
||
| 92 | * @api |
||
| 93 | * |
||
| 94 | * @since 0.1.0 |
||
| 95 | * |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | public function getUrl () |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The board's unique identifier. |
||
| 105 | * |
||
| 106 | * @api |
||
| 107 | * |
||
| 108 | * @since 0.1.0 |
||
| 109 | * |
||
| 110 | * @return int |
||
| 111 | */ |
||
| 112 | public function getId () |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The board's name. |
||
| 119 | * |
||
| 120 | * @api |
||
| 121 | * |
||
| 122 | * @since 0.1.0 |
||
| 123 | * |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | public function getName () |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The board's description. |
||
| 133 | * |
||
| 134 | * @api |
||
| 135 | * |
||
| 136 | * @since 0.1.0 |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getDescription () |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Creation time. |
||
| 147 | * |
||
| 148 | * @api |
||
| 149 | * |
||
| 150 | * @since 0.1.0 |
||
| 151 | * |
||
| 152 | * @return \DateTime |
||
| 153 | */ |
||
| 154 | public function getCreatedAt () |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Last update time. |
||
| 163 | * |
||
| 164 | * @api |
||
| 165 | * |
||
| 166 | * @since 0.1.0 |
||
| 167 | * |
||
| 168 | * @return \DateTime |
||
| 169 | */ |
||
| 170 | public function getUpdatedAt () |
||
| 176 | |||
| 177 | // ================================================================================================================= |
||
| 178 | // Columns functions |
||
| 179 | // ================================================================================================================= |
||
| 180 | |||
| 181 | /** |
||
| 182 | * The board's visible columns. |
||
| 183 | * |
||
| 184 | * @api |
||
| 185 | * |
||
| 186 | * @since 0.1.0 |
||
| 187 | * |
||
| 188 | * @return PulseColumn[] |
||
| 189 | */ |
||
| 190 | public function getColumns () |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Create a new column for the current board. |
||
| 202 | * |
||
| 203 | * If you are creating a status column, use the constants available in the **PulseColumnColorValue** class to match |
||
| 204 | * the colors. Keep in mind this array cannot have a key higher than 11 nor can it be an associative array. Here's |
||
| 205 | * an example of how to match statuses with specific colors. |
||
| 206 | * |
||
| 207 | * ```php |
||
| 208 | * $labels = array( |
||
| 209 | * PulseColumnColorValue::Orange => "Working on it", |
||
| 210 | * PulseColumnColorValue::L_Green => "Done", |
||
| 211 | * PulseColumnColorValue::Red => "Delayed" |
||
| 212 | * ); |
||
| 213 | * ``` |
||
| 214 | * |
||
| 215 | * @api |
||
| 216 | * |
||
| 217 | * @param string $title The title of the column. This title will automatically be "slugified" and become the ID |
||
| 218 | * of the column. |
||
| 219 | * @param string $type The type of value that this column will use. Either use the available constants in the |
||
| 220 | * PulseColumn class or use the following strings: "date", "person", "status", "text". |
||
| 221 | * @param array $labels If the column type will be "status," then this array will be the values for each of the |
||
| 222 | * colors. |
||
| 223 | * |
||
| 224 | * @see PulseColumn::Date PulseColumn::Date |
||
| 225 | * @see PulseColumn::Person PulseColumn::Person |
||
| 226 | * @see PulseColumn::Status PulseColumn::Status |
||
| 227 | * @see PulseColumn::Text PulseColumn::Text |
||
| 228 | * @see PulseColumnColorValue::Orange PulseColumnColorValue::Orange |
||
| 229 | * @see PulseColumnColorValue::L_Green PulseColumnColorValue::L_Green |
||
| 230 | * @see PulseColumnColorValue::Red PulseColumnColorValue::Red |
||
| 231 | * @see PulseColumnColorValue::Blue PulseColumnColorValue::Blue |
||
| 232 | * @see PulseColumnColorValue::Purple PulseColumnColorValue::Purple |
||
| 233 | * @see PulseColumnColorValue::Grey PulseColumnColorValue::Grey |
||
| 234 | * @see PulseColumnColorValue::Green PulseColumnColorValue::Green |
||
| 235 | * @see PulseColumnColorValue::L_Blue PulseColumnColorValue::L_Blue |
||
| 236 | * @see PulseColumnColorValue::Gold PulseColumnColorValue::Gold |
||
| 237 | * @see PulseColumnColorValue::Yellow PulseColumnColorValue::Yellow |
||
| 238 | * @see PulseColumnColorValue::Black PulseColumnColorValue::Black |
||
| 239 | * |
||
| 240 | * @since 0.1.0 |
||
| 241 | * |
||
| 242 | * @throws ArgumentMismatchException Status definitions were defined yet the type of the column was not a status |
||
| 243 | * type column |
||
| 244 | * @throws InvalidArraySizeException The array containing the value of statuses has a key larger than the |
||
| 245 | * supported 10 indices |
||
| 246 | * |
||
| 247 | * @return $this This instance will be updated to have updated information to reflect the new column that was |
||
| 248 | * created |
||
| 249 | */ |
||
| 250 | public function createColumn ($title, $type, $labels = array()) |
||
| 275 | |||
| 276 | // ================================================================================================================= |
||
| 277 | // Group functions |
||
| 278 | // ================================================================================================================= |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Get all of the groups belonging to a board. |
||
| 282 | * |
||
| 283 | * A group is defined as the colorful headers that split up pulses into categories. |
||
| 284 | * |
||
| 285 | * @api |
||
| 286 | * |
||
| 287 | * @param bool $showArchived Set to true if you would like to get archived groups in a board as well |
||
| 288 | * |
||
| 289 | * @since 0.1.0 |
||
| 290 | * |
||
| 291 | * @return PulseGroup[] |
||
| 292 | */ |
||
| 293 | public function getGroups ($showArchived = NULL) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Create a new group in a board |
||
| 305 | * |
||
| 306 | * @api |
||
| 307 | * |
||
| 308 | * @param string $title The title of the board |
||
| 309 | * |
||
| 310 | * @since 0.1.0 |
||
| 311 | * |
||
| 312 | * @return PulseGroup |
||
| 313 | */ |
||
| 314 | public function createGroup ($title) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Delete a group from a board |
||
| 328 | * |
||
| 329 | * @api |
||
| 330 | * |
||
| 331 | * @param string $groupId The group ID to be deleted |
||
| 332 | * |
||
| 333 | * @since 0.1.0 |
||
| 334 | */ |
||
| 335 | public function deleteGroup ($groupId) |
||
| 341 | |||
| 342 | // ================================================================================================================= |
||
| 343 | // Pulse functions |
||
| 344 | // ================================================================================================================= |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return Pulse[] |
||
| 348 | */ |
||
| 349 | public function getPulses () |
||
| 364 | |||
| 365 | public function createPulse ($name, $owner, $groupId = NULL) |
||
| 382 | |||
| 383 | View Code Duplication | private function pulseInjection (&$result) |
|
| 390 | |||
| 391 | // ================================================================================================================= |
||
| 392 | // Board functions |
||
| 393 | // ================================================================================================================= |
||
| 394 | |||
| 395 | View Code Duplication | public function archiveBoard () |
|
| 404 | |||
| 405 | public static function createBoard ($name, $userId, $description = NULL) |
||
| 419 | |||
| 420 | public static function getBoards ($params = array()) |
||
| 426 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: