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 |
||
| 19 | class TaskHelper extends Base |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Local cache for project columns. |
||
| 23 | * |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | private $columns = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get the color list. |
||
| 30 | * |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public function getColors() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Return the list recurrence triggers. |
||
| 40 | * |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | public function recurrenceTriggers() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Return the list recurrence timeframes. |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function recurrenceTimeframes() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Return the list options to calculate recurrence due date. |
||
| 60 | * |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | public function recurrenceBasedates() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Display a select field of title. |
||
| 70 | * |
||
| 71 | * @param array $values Form values |
||
| 72 | * @param array $errors Form errors |
||
| 73 | * |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | public function selectTitle(array $values, array $errors) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Display a select field of description. |
||
| 86 | * |
||
| 87 | * @param array $values Form values |
||
| 88 | * @param array $errors Form errors |
||
| 89 | * |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | public function selectDescription(array $values, array $errors) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Display a select field of tags. |
||
| 102 | * |
||
| 103 | * @param array $values Form values |
||
| 104 | * @param array $targs Form tags |
||
| 105 | * |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function selectTags(array $project, array $tags = []) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Display a select field of color. |
||
| 132 | * |
||
| 133 | * @param array $values Form values |
||
| 134 | * |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | public function selectColor(array $values) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Display a select field of project. |
||
| 148 | * |
||
| 149 | * @param array $projects |
||
| 150 | * @param array $values Form values |
||
| 151 | * @param array $errors Form errors |
||
| 152 | * @param array $attributes |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | public function selectProject(array $projects, array $values, array $errors = [], array $attributes = []) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Display a select field of assignee. |
||
| 168 | * |
||
| 169 | * @param array $users |
||
| 170 | * @param array $values Form values |
||
| 171 | * @param array $errors Form errors |
||
| 172 | * @param array $attributes |
||
| 173 | * |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | View Code Duplication | public function selectAssignee(array $users, array $values, array $errors = [], array $attributes = []) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Display a select field of category. |
||
| 192 | * |
||
| 193 | * @param array $categories |
||
| 194 | * @param array $values Form values |
||
| 195 | * @param array $errors Form errors |
||
| 196 | * @param array $attributes |
||
| 197 | * @param bool allow_one_item |
||
| 198 | * |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | View Code Duplication | public function selectCategory(array $categories, array $values, array $errors = [], array $attributes = [], $allow_one_item = false) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * Display a select field of swimlane. |
||
| 216 | * |
||
| 217 | * @param array $swimlanes |
||
| 218 | * @param array $values Form values |
||
| 219 | * @param array $errors Form errors |
||
| 220 | * @param array $attributes |
||
| 221 | * |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | View Code Duplication | public function selectSwimlane(array $swimlanes, array $values, array $errors = [], array $attributes = []) |
|
| 236 | |||
| 237 | /** |
||
| 238 | * Display a select field of column. |
||
| 239 | * |
||
| 240 | * @param array $columns |
||
| 241 | * @param array $values Form values |
||
| 242 | * @param array $errors Form errors |
||
| 243 | * @param array $attributes |
||
| 244 | * |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | View Code Duplication | public function selectColumn(array $columns, array $values, array $errors = [], array $attributes = []) |
|
| 256 | |||
| 257 | /** |
||
| 258 | * Display a select field of column. |
||
| 259 | * |
||
| 260 | * @param array $project |
||
| 261 | * @param array $values Form values |
||
| 262 | * |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function selectPriority(array $project, array $values) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Display a select field of score. |
||
| 284 | * |
||
| 285 | * @param array $values Form values |
||
| 286 | * @param array $errors Form errors |
||
| 287 | * @param array $attributes |
||
| 288 | * |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | public function selectScore(array $values, array $errors = [], array $attributes = []) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Display a select field of reference. |
||
| 303 | * |
||
| 304 | * @param array $values Form values |
||
| 305 | * @param array $errors Form errors |
||
| 306 | * @param array $attributes |
||
| 307 | * |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | View Code Duplication | public function selectReference(array $values, array $errors = [], array $attributes = []) |
|
| 319 | |||
| 320 | /** |
||
| 321 | * Display a select field of time estimated. |
||
| 322 | * |
||
| 323 | * @param array $values Form values |
||
| 324 | * @param array $errors Form errors |
||
| 325 | * @param array $attributes |
||
| 326 | * |
||
| 327 | * @return string |
||
| 328 | */ |
||
| 329 | View Code Duplication | public function selectTimeEstimated(array $values, array $errors = [], array $attributes = []) |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Display a select field of time spent. |
||
| 342 | * |
||
| 343 | * @param array $values Form values |
||
| 344 | * @param array $errors Form errors |
||
| 345 | * @param array $attributes |
||
| 346 | * |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | View Code Duplication | public function selectTimeSpent(array $values, array $errors = [], array $attributes = []) |
|
| 359 | |||
| 360 | /** |
||
| 361 | * Display a select field of start date. |
||
| 362 | * |
||
| 363 | * @param array $values Form values |
||
| 364 | * @param array $errors Form errors |
||
| 365 | * @param array $attributes |
||
| 366 | * |
||
| 367 | * @return string |
||
| 368 | */ |
||
| 369 | public function selectStartDate(array $values, array $errors = [], array $attributes = []) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Display a select field of due date. |
||
| 378 | * |
||
| 379 | * @param array $values Form values |
||
| 380 | * @param array $errors Form errors |
||
| 381 | * @param array $attributes |
||
| 382 | * |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | public function selectDueDate(array $values, array $errors = [], array $attributes = []) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Display a select field of progress. |
||
| 394 | * |
||
| 395 | * @param array $values Form values |
||
| 396 | * @param array $errors Form errors |
||
| 397 | * @param array $attributes |
||
| 398 | * |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | View Code Duplication | public function selectProgress(array $values, array $errors = [], array $attributes = []) |
|
| 413 | |||
| 414 | /** |
||
| 415 | * Format the priority. |
||
| 416 | * |
||
| 417 | * @param array $project |
||
| 418 | * @param array $task |
||
| 419 | * |
||
| 420 | * @return string |
||
| 421 | */ |
||
| 422 | public function formatPriority(array $project, array $task) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Returns the task progress. |
||
| 437 | * |
||
| 438 | * @param array $task |
||
| 439 | * |
||
| 440 | * @return int |
||
| 441 | */ |
||
| 442 | public function getProgress($task) |
||
| 450 | } |
||
| 451 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.