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 |
||
| 21 | abstract class Controller extends Base |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Check webhook token. |
||
| 25 | */ |
||
| 26 | protected function checkWebhookToken() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Common method to get a task for task views. |
||
| 35 | * |
||
| 36 | * @throws PageNotFoundException |
||
| 37 | * @throws AccessForbiddenException |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | protected function getTask() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get Task or Project file. |
||
| 59 | * |
||
| 60 | * @throws PageNotFoundException |
||
| 61 | * @throws AccessForbiddenException |
||
| 62 | * |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | protected function getFile() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Common method to get a project. |
||
| 93 | * |
||
| 94 | * @param int $project_id Default project id |
||
| 95 | * |
||
| 96 | * @throws PageNotFoundException |
||
| 97 | * |
||
| 98 | * @return array |
||
| 99 | */ |
||
| 100 | protected function getProject($project_id = 0) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Common method to get the user. |
||
| 113 | * |
||
| 114 | * @throws PageNotFoundException |
||
| 115 | * @throws AccessForbiddenException |
||
| 116 | * |
||
| 117 | * @return array |
||
| 118 | */ |
||
| 119 | View Code Duplication | protected function getUser() |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Get the current subtask. |
||
| 136 | * |
||
| 137 | * @throws PageNotFoundException |
||
| 138 | * |
||
| 139 | * @return array |
||
| 140 | */ |
||
| 141 | View Code Duplication | protected function getSubtask() |
|
| 151 | } |
||
| 152 |
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.