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 |
||
| 24 | class PulseBoard extends ApiObject |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * The suffix that is appended to the URL to access functionality for certain objects |
||
| 28 | * |
||
| 29 | * @internal |
||
| 30 | */ |
||
| 31 | const API_PREFIX = "boards"; |
||
| 32 | |||
| 33 | // ================================================================================================================ |
||
| 34 | // Instance Variables |
||
| 35 | // ================================================================================================================ |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The resource's URL. |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $url; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The board's unique identifier. |
||
| 46 | * |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | protected $id; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * The board's name. |
||
| 53 | * |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $name; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The board's description. |
||
| 60 | * |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | protected $description; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The board's visible columns. |
||
| 67 | * |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $columns; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The board's visible groups. |
||
| 74 | * |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $groups; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Creation time. |
||
| 81 | * |
||
| 82 | * @var \DateTime |
||
| 83 | */ |
||
| 84 | protected $created_at; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Last update time. |
||
| 88 | * |
||
| 89 | * @var \DateTime |
||
| 90 | */ |
||
| 91 | protected $updated_at; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Whether or not groups have been fetched. Group data comes from both a unique API call and from the initial call |
||
| 95 | * of getting the board data, so this data is merged; this boolean is to avoid fetching this data twice. |
||
| 96 | * |
||
| 97 | * @var bool |
||
| 98 | */ |
||
| 99 | private $groupsFetched = false; |
||
| 100 | |||
| 101 | // ================================================================================================================ |
||
| 102 | // Getter functions |
||
| 103 | // ================================================================================================================ |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The resource's URL. |
||
| 107 | * |
||
| 108 | * @api |
||
| 109 | * @since 0.1.0 |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public function getUrl() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The board's unique identifier. |
||
| 119 | * |
||
| 120 | * @api |
||
| 121 | * @since 0.1.0 |
||
| 122 | * @return int |
||
| 123 | */ |
||
| 124 | public function getId() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The board's name. |
||
| 131 | * |
||
| 132 | * @api |
||
| 133 | * @since 0.1.0 |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | public function getName() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The board's description. |
||
| 143 | * |
||
| 144 | * @api |
||
| 145 | * @since 0.1.0 |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | public function getDescription() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * The board's visible columns. |
||
| 155 | * |
||
| 156 | * @api |
||
| 157 | * @since 0.1.0 |
||
| 158 | * @return PulseColumn[] |
||
| 159 | */ |
||
| 160 | public function getColumns() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Creation time. |
||
| 172 | * |
||
| 173 | * @api |
||
| 174 | * @since 0.1.0 |
||
| 175 | * @return \DateTime |
||
| 176 | */ |
||
| 177 | public function getCreatedAt() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Last update time. |
||
| 186 | * |
||
| 187 | * @api |
||
| 188 | * @since 0.1.0 |
||
| 189 | * @return \DateTime |
||
| 190 | */ |
||
| 191 | public function getUpdatedAt() |
||
| 197 | |||
| 198 | // ================================================================================================================ |
||
| 199 | // Subscriber functions |
||
| 200 | // ================================================================================================================ |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get the users who are subscribed to this board |
||
| 204 | * |
||
| 205 | * @param array $params |
||
| 206 | * |
||
| 207 | * @return PulseUser[] |
||
| 208 | */ |
||
| 209 | public function getSubscribers ($params = array()) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Subscriber a user to a board |
||
| 218 | * |
||
| 219 | * @param int|PulseUser $user_id The user that will be subscribed to the board |
||
| 220 | * @param bool|null $as_admin Set to true if the user will be an admin of the board |
||
| 221 | */ |
||
| 222 | View Code Duplication | public function addSubscriber ($user_id, $as_admin = NULL) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * Unsubscribe a user from this board |
||
| 240 | * |
||
| 241 | * @param int|PulseUser $user_id The user that will be unsubscribed from the board |
||
| 242 | */ |
||
| 243 | View Code Duplication | public function removeSubscriber ($user_id) |
|
| 254 | |||
| 255 | // ================================================================================================================ |
||
| 256 | // Columns functions |
||
| 257 | // ================================================================================================================ |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Create a new column for the current board. |
||
| 261 | * |
||
| 262 | * If you are creating a status column, use the constants available in the **PulseColumnColorValue** class to match the |
||
| 263 | * colors. Keep in mind this array cannot have a key higher than 11 nor can it be an associative array. Here's an |
||
| 264 | * example of how to match statuses with specific colors. |
||
| 265 | * |
||
| 266 | * ```php |
||
| 267 | * $labels = array( |
||
| 268 | * PulseColumnColorValue::Orange => "Working on it", |
||
| 269 | * PulseColumnColorValue::L_Green => "Done", |
||
| 270 | * PulseColumnColorValue::Red => "Delayed" |
||
| 271 | * ); |
||
| 272 | * ``` |
||
| 273 | * |
||
| 274 | * @api |
||
| 275 | * |
||
| 276 | * @param string $title The title of the column. This title will automatically be "slugified" and become the ID |
||
| 277 | * of the column. |
||
| 278 | * @param string $type The type of value that this column will use. Either use the available constants in the |
||
| 279 | * PulseColumn class or use the following strings: "date", "person", "status", "text". |
||
| 280 | * @param array $labels If the column type will be "status," then this array will be the values for each of the |
||
| 281 | * colors. |
||
| 282 | * |
||
| 283 | * @see PulseColumn::Date PulseColumn::Date |
||
| 284 | * @see PulseColumn::Person PulseColumn::Person |
||
| 285 | * @see PulseColumn::Status PulseColumn::Status |
||
| 286 | * @see PulseColumn::Text PulseColumn::Text |
||
| 287 | * @see PulseColumnColorValue::Orange PulseColumnColorValue::Orange |
||
| 288 | * @see PulseColumnColorValue::L_Green PulseColumnColorValue::L_Green |
||
| 289 | * @see PulseColumnColorValue::Red PulseColumnColorValue::Red |
||
| 290 | * @see PulseColumnColorValue::Blue PulseColumnColorValue::Blue |
||
| 291 | * @see PulseColumnColorValue::Purple PulseColumnColorValue::Purple |
||
| 292 | * @see PulseColumnColorValue::Grey PulseColumnColorValue::Grey |
||
| 293 | * @see PulseColumnColorValue::Green PulseColumnColorValue::Green |
||
| 294 | * @see PulseColumnColorValue::L_Blue PulseColumnColorValue::L_Blue |
||
| 295 | * @see PulseColumnColorValue::Gold PulseColumnColorValue::Gold |
||
| 296 | * @see PulseColumnColorValue::Yellow PulseColumnColorValue::Yellow |
||
| 297 | * @see PulseColumnColorValue::Black PulseColumnColorValue::Black |
||
| 298 | * |
||
| 299 | * @since 0.1.0 |
||
| 300 | * |
||
| 301 | * @throws ArgumentMismatchException Status definitions were defined yet the type of the column was not a status |
||
| 302 | * type column |
||
| 303 | * @throws InvalidArraySizeException The array containing the value of statuses has a key larger than the |
||
| 304 | * supported 10 indices |
||
| 305 | * |
||
| 306 | * @return $this This instance will be updated to have updated information to reflect the new column that was |
||
| 307 | * created |
||
| 308 | */ |
||
| 309 | public function createColumn ($title, $type, $labels = array()) |
||
| 334 | |||
| 335 | // ================================================================================================================ |
||
| 336 | // Group functions |
||
| 337 | // ================================================================================================================ |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Get all of the groups belonging to a board. |
||
| 341 | * |
||
| 342 | * A group is defined as the colorful headers that split up pulses into categories. |
||
| 343 | * |
||
| 344 | * @api |
||
| 345 | * |
||
| 346 | * @param bool $showArchived Set to true if you would like to get archived groups in a board as well |
||
| 347 | * |
||
| 348 | * @since 0.1.0 |
||
| 349 | * |
||
| 350 | * @return PulseGroup[] |
||
| 351 | */ |
||
| 352 | public function getGroups ($showArchived = false) |
||
| 366 | |||
| 367 | public function createGroup ($title) |
||
| 378 | |||
| 379 | private function fetchGroups ($showArchived) |
||
| 387 | |||
| 388 | // ================================================================================================================ |
||
| 389 | // Pulse functions |
||
| 390 | // ================================================================================================================ |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @return Pulse[] |
||
| 394 | */ |
||
| 395 | public function getPulses () |
||
| 410 | |||
| 411 | public function createPulse ($name, $owner, $group_id = null) |
||
| 428 | |||
| 429 | View Code Duplication | private function pulseInjection (&$result) |
|
| 436 | |||
| 437 | // ================================================================================================================ |
||
| 438 | // Board functions |
||
| 439 | // ================================================================================================================ |
||
| 440 | |||
| 441 | View Code Duplication | public function archiveBoard () |
|
| 450 | |||
| 451 | public static function createBoard ($name, $user_id, $description = NULL) |
||
| 465 | |||
| 466 | public static function getBoards ($params = array()) |
||
| 472 | } |
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.